mirror of
https://github.com/tonytins/tomas.git
synced 2025-03-21 15:21:21 +00:00
Unit tests
- Renamed GlobalUsings.cs to Usings.cs - Refractored SysFS - Seperated building of the terminal and unit tests - To save on resources, the unit tests job on runs on Ubuntu
This commit is contained in:
parent
19f7483fbd
commit
c10e753c39
11 changed files with 237 additions and 127 deletions
19
.github/workflows/dotnet.yml
vendored
19
.github/workflows/dotnet.yml
vendored
|
@ -28,3 +28,22 @@ jobs:
|
||||||
run: dotnet restore src/Tomas.Terminal
|
run: dotnet restore src/Tomas.Terminal
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build src/Tomas.Terminal -c Release --no-restore
|
run: dotnet build src/Tomas.Terminal -c Release --no-restore
|
||||||
|
|
||||||
|
test:
|
||||||
|
timeout-minutes: 15
|
||||||
|
continue-on-error: true
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
dotnet: ["6.0.x"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: ${{ matrix.dotnet }}
|
||||||
|
- name: Install test dependencies
|
||||||
|
run: dotnet restore src/Tomas.Tests
|
||||||
|
- name: Test
|
||||||
|
run: dotnet test src --no-restore --debug
|
|
@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Terminal", "Tomas.Ter
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Kernel", "Tomas.Kernel\Tomas.Kernel.csproj", "{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Kernel", "Tomas.Kernel\Tomas.Kernel.csproj", "{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tomas.Tests", "Tomas.Tests\Tomas.Tests.csproj", "{76AD2140-2975-43DA-89A9-0BEC70B2ECDD}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -44,6 +46,10 @@ Global
|
||||||
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B70BDFD5-64BA-4FCE-A00F-DDD209C2C0FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{76AD2140-2975-43DA-89A9-0BEC70B2ECDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{76AD2140-2975-43DA-89A9-0BEC70B2ECDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{76AD2140-2975-43DA-89A9-0BEC70B2ECDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{76AD2140-2975-43DA-89A9-0BEC70B2ECDD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
0
src/Tomas.Interface/Usings.cs
Normal file
0
src/Tomas.Interface/Usings.cs
Normal file
|
@ -8,152 +8,138 @@ namespace Tomas.Kernel;
|
||||||
|
|
||||||
static class SysFS
|
static class SysFS
|
||||||
{
|
{
|
||||||
// The root directory of the file system
|
// The root directory of the file system
|
||||||
public const string ROOT_DIR = "0:\\";
|
public const string ROOT_DIR = "0:\\";
|
||||||
// The system directory, located in the root directory
|
// The system directory, located in the root directory
|
||||||
static string SYSTEM_DIR = $"{ROOT_DIR}\\SYSTEM\\";
|
static string SYSTEM_DIR = $"{ROOT_DIR}\\SYSTEM\\";
|
||||||
|
|
||||||
static string LOG_FILE = $"{SYSTEM_DIR}system.log";
|
static string LOG_FILE = $"{SYSTEM_DIR}system.log";
|
||||||
|
|
||||||
public const string FS_ERROR = "File system disabled.";
|
public const string FS_ERROR = "File system disabled.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An instance of the CosmosVFS class, used for accessing the virtual file system
|
/// An instance of the CosmosVFS class, used for accessing the virtual file system
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static CosmosVFS fileSystem = new();
|
static CosmosVFS fileSystem = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the file system by creating the system directory and sysinfo.txt file
|
/// Initializes the file system by creating the system directory and sysinfo.txt file
|
||||||
/// and setting the IsFSActive property of the SysMeta class to true
|
/// and setting the IsFSActive property of the SysMeta class to true
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var createSysFiles = "Creating system files.";
|
// File to store system information
|
||||||
var setSysPref = "Writing system info.";
|
const string sysInfoFile = "sysinfo.txt";
|
||||||
var fsSuccess = "File system succesfully initialized.";
|
|
||||||
var sysInfoFile = "sysinfo.txt";
|
|
||||||
|
|
||||||
// Register the CosmosVFS instance as the virtual file system
|
// Create system directory if it doesn't exist
|
||||||
VFSManager.RegisterVFS(fileSystem);
|
if (!Directory.Exists(SYSTEM_DIR))
|
||||||
|
fileSystem.CreateDirectory(SYSTEM_DIR);
|
||||||
|
|
||||||
// Create the system directory
|
// Create system log file if it doesn't exist
|
||||||
if (!Directory.Exists(SYSTEM_DIR))
|
if (!File.Exists($"{SYSTEM_DIR}{LOG_FILE}"))
|
||||||
fileSystem.CreateDirectory(SYSTEM_DIR);
|
fileSystem.CreateFile($"{SYSTEM_DIR}{LOG_FILE}");
|
||||||
|
|
||||||
// Create the system.log file in the system directory
|
// Create sysinfo.txt file if it doesn't exist
|
||||||
if (!File.Exists($"{SYSTEM_DIR}{LOG_FILE}"))
|
if (!File.Exists($"{SYSTEM_DIR}{sysInfoFile}"))
|
||||||
fileSystem.CreateFile($"{SYSTEM_DIR}{LOG_FILE}");
|
fileSystem.CreateFile($"{SYSTEM_DIR}{sysInfoFile}");
|
||||||
|
|
||||||
Console.WriteLine(createSysFiles);
|
// Write system name, version, and build number to sysinfo.txt file
|
||||||
File.AppendAllText(LOG_FILE, createSysFiles);
|
File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{SysMeta.NAME} v{SysMeta.VERSION} ({SysMeta.BuildNumber})");
|
||||||
|
|
||||||
// Create the sysinfo.txt file in the system directory
|
// Set IsFSEnabled property of SysMeta class to true
|
||||||
if (!File.Exists($"{SYSTEM_DIR}{sysInfoFile}"))
|
SysMeta.IsFSEnabled = true;
|
||||||
fileSystem.CreateFile($"{SYSTEM_DIR}{sysInfoFile}");
|
|
||||||
|
|
||||||
Console.WriteLine(setSysPref);
|
// Read contents of sysinfo.txt file and print to console
|
||||||
|
var systemInfo = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
||||||
|
Console.WriteLine(systemInfo);
|
||||||
|
}
|
||||||
|
catch (Exception err)
|
||||||
|
{
|
||||||
|
// Print error message if an exception is caught
|
||||||
|
Console.WriteLine($"{err.Message}{Environment.NewLine}Warning: Error messages will not logged.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File.AppendAllText(LOG_FILE, setSysPref);
|
|
||||||
|
|
||||||
// Write the system name, version, and build number to the sysinfo.txt file
|
|
||||||
File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{SysMeta.NAME} v{SysMeta.VERSION} ({SysMeta.BuildNumber})");
|
|
||||||
|
|
||||||
Console.WriteLine(fsSuccess);
|
/// <summary>
|
||||||
File.AppendAllText(LOG_FILE, fsSuccess);
|
/// Creates a new directory at the specified path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directory">directory</param>
|
||||||
|
public static void CreateDirectory(string directory)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// If file system isn't enabeld, throw exception
|
||||||
|
if (!SysMeta.IsFSEnabled)
|
||||||
|
throw new IOException(FS_ERROR);
|
||||||
|
|
||||||
// Set the IsFSActive property of the SysMeta class to true
|
// Create the directory using the CosmosVFS instance
|
||||||
SysMeta.IsFSEnabled = true;
|
if (!Directory.Exists($"{ROOT_DIR}\\{directory}"))
|
||||||
|
fileSystem.CreateDirectory($"{ROOT_DIR}\\{directory}");
|
||||||
|
}
|
||||||
|
catch (IOException err)
|
||||||
|
{
|
||||||
|
// If an exception is caught, print an error message indicating the error
|
||||||
|
Console.WriteLine(err.Message);
|
||||||
|
File.AppendAllText(LOG_FILE, err.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read the contents of the sysinfo.txt file and print it to the console
|
/// <summary>
|
||||||
var systemInfo = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
/// Creates a new file at the specified path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">file path</param>
|
||||||
|
/// <param name="file">file</param>
|
||||||
|
public static void CreateFile(string path, string file)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// If file system isn't enabeld, throw exception
|
||||||
|
if (!SysMeta.IsFSEnabled)
|
||||||
|
throw new IOException(FS_ERROR);
|
||||||
|
|
||||||
Console.WriteLine(systemInfo);
|
// Create the file using the CosmosVFS instance
|
||||||
}
|
if (!File.Exists($"{ROOT_DIR}\\{path}\\{file}"))
|
||||||
catch (Exception err)
|
fileSystem.CreateFile($"{ROOT_DIR}\\{path}\\{file}");
|
||||||
{
|
}
|
||||||
// If an exception is caught, print an error message indicating that the file system failed to load
|
catch (IOException err)
|
||||||
Console.WriteLine($"{err.Message}{Environment.NewLine}Warning: Error messages will not logged.");
|
{
|
||||||
}
|
// If an exception is caught, print an error message indicating the error
|
||||||
}
|
Console.WriteLine(err.Message);
|
||||||
|
File.AppendAllText(LOG_FILE, err.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new directory at the specified path
|
/// Lists all directories in the specified path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="directory">directory</param>
|
/// <param name="path">path to directory</param>
|
||||||
public static void CreateDirectory(string directory)
|
/// <returns>returns a list of directories</returns>
|
||||||
{
|
public static string[] ListDirectories(string path)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
// If file system isn't enabeld, throw exception
|
{
|
||||||
if (!SysMeta.IsFSEnabled)
|
// If file system isn't enabeld, throw exception
|
||||||
throw new IOException(FS_ERROR);
|
if (!SysMeta.IsFSEnabled)
|
||||||
|
throw new IOException(FS_ERROR);
|
||||||
|
|
||||||
// Create the directory using the CosmosVFS instance
|
// Get the directories in the specified path using the Directory.GetDirectories method
|
||||||
if (!Directory.Exists($"{ROOT_DIR}\\{directory}"))
|
var dirs = Directory.GetDirectories(path);
|
||||||
fileSystem.CreateDirectory($"{ROOT_DIR}\\{directory}");
|
|
||||||
}
|
|
||||||
catch (IOException err)
|
|
||||||
{
|
|
||||||
// If an exception is caught, print an error message indicating the error
|
|
||||||
Console.WriteLine(err.Message);
|
|
||||||
File.AppendAllText(LOG_FILE, err.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
// Return the directories
|
||||||
/// Creates a new file at the specified path
|
return dirs;
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="path">file path</param>
|
catch (IOException err)
|
||||||
/// <param name="file">file</param>
|
{
|
||||||
public static void CreateFile(string path, string file)
|
// If an exception is caught, print an error message indicating the error
|
||||||
{
|
Console.WriteLine(err.Message);
|
||||||
try
|
File.AppendAllText(LOG_FILE, err.Message);
|
||||||
{
|
|
||||||
// If file system isn't enabeld, throw exception
|
|
||||||
if (!SysMeta.IsFSEnabled)
|
|
||||||
throw new IOException(FS_ERROR);
|
|
||||||
|
|
||||||
// Create the file using the CosmosVFS instance
|
throw;
|
||||||
if (!File.Exists($"{ROOT_DIR}\\{path}\\{file}"))
|
}
|
||||||
fileSystem.CreateFile($"{ROOT_DIR}\\{path}\\{file}");
|
}
|
||||||
}
|
|
||||||
catch (IOException err)
|
|
||||||
{
|
|
||||||
// If an exception is caught, print an error message indicating the error
|
|
||||||
Console.WriteLine(err.Message);
|
|
||||||
File.AppendAllText(LOG_FILE, err.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Lists all directories in the specified path
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">path to directory</param>
|
|
||||||
/// <returns>returns a list of directories</returns>
|
|
||||||
public static string[] ListDirectories(string path)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// If file system isn't enabeld, throw exception
|
|
||||||
if (!SysMeta.IsFSEnabled)
|
|
||||||
throw new IOException(FS_ERROR);
|
|
||||||
|
|
||||||
// Get the directories in the specified path using the Directory.GetDirectories method
|
|
||||||
var dirs = Directory.GetDirectories(path);
|
|
||||||
|
|
||||||
// Return the directories
|
|
||||||
return dirs;
|
|
||||||
}
|
|
||||||
catch (IOException err)
|
|
||||||
{
|
|
||||||
// If an exception is caught, print an error message indicating the error
|
|
||||||
Console.WriteLine(err.Message);
|
|
||||||
File.AppendAllText(LOG_FILE, err.Message);
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/Tomas.Tests/Shell/MockProgram.cs
Normal file
16
src/Tomas.Tests/Shell/MockProgram.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
In jurisdictions that recognize copyright waivers, I've waived all copyright
|
||||||
|
and related or neighboring rights for to this project. In areas where these
|
||||||
|
waivers are not recognized, BSD-3-Clause is enforced.
|
||||||
|
See the (UN)LICENSE file in the project root for more information.
|
||||||
|
*/
|
||||||
|
namespace Tomas.Tests.Shell;
|
||||||
|
|
||||||
|
internal class MockProgram : IProgram
|
||||||
|
{
|
||||||
|
public bool Run(IShell shell)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Test Program.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
17
src/Tomas.Tests/Shell/MockShell.cs
Normal file
17
src/Tomas.Tests/Shell/MockShell.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
In jurisdictions that recognize copyright waivers, I've waived all copyright
|
||||||
|
and related or neighboring rights for to this project. In areas where these
|
||||||
|
waivers are not recognized, BSD-3-Clause is enforced.
|
||||||
|
See the (UN)LICENSE file in the project root for more information.
|
||||||
|
*/
|
||||||
|
namespace Tomas.Tests.Shell;
|
||||||
|
|
||||||
|
internal class MockShell : IShell
|
||||||
|
{
|
||||||
|
public string? ReadLine { get; }
|
||||||
|
|
||||||
|
public Dictionary<string, IProgram> Programs => new()
|
||||||
|
{
|
||||||
|
{ "test", new MockProgram() },
|
||||||
|
};
|
||||||
|
}
|
26
src/Tomas.Tests/ShellTests.cs
Normal file
26
src/Tomas.Tests/ShellTests.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
In jurisdictions that recognize copyright waivers, I've waived all copyright
|
||||||
|
and related or neighboring rights for to this project. In areas where these
|
||||||
|
waivers are not recognized, BSD-3-Clause is enforced.
|
||||||
|
See the (UN)LICENSE file in the project root for more information.
|
||||||
|
*/
|
||||||
|
using Tomas.Tests.Shell;
|
||||||
|
|
||||||
|
namespace Tomas.Tests;
|
||||||
|
|
||||||
|
public class ShellTests
|
||||||
|
{
|
||||||
|
// Create a new instance of the mock shell
|
||||||
|
readonly MockShell _mockShell = new();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProgramTest()
|
||||||
|
{
|
||||||
|
// Create a mock program
|
||||||
|
var program = new MockProgram();
|
||||||
|
|
||||||
|
// Assert that the Run method of the program and returns true when passed the shell object.
|
||||||
|
Assert.True(program.Run(_mockShell));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/Tomas.Tests/Tomas.Tests.csproj
Normal file
29
src/Tomas.Tests/Tomas.Tests.csproj
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Tomas.Core\Tomas.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\Tomas.Interface\Tomas.Interface.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
11
src/Tomas.Tests/Usings.cs
Normal file
11
src/Tomas.Tests/Usings.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
In jurisdictions that recognize copyright waivers, I've waived all copyright
|
||||||
|
and related or neighboring rights for to this project. In areas where these
|
||||||
|
waivers are not recognized, BSD-3-Clause is enforced.
|
||||||
|
See the (UN)LICENSE file in the project root for more information.
|
||||||
|
*/
|
||||||
|
global using Xunit;
|
||||||
|
global using System.Diagnostics.CodeAnalysis;
|
||||||
|
global using System.Diagnostics;
|
||||||
|
global using Tomas.Core;
|
||||||
|
global using Tomas.Interface;
|
Loading…
Add table
Reference in a new issue