mirror of
https://github.com/tonytins/tomas.git
synced 2025-03-21 23:22:19 +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
|
@ -30,54 +30,40 @@ static class SysFS
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
|
|
||||||
// Create the system directory
|
|
||||||
if (!Directory.Exists(SYSTEM_DIR))
|
if (!Directory.Exists(SYSTEM_DIR))
|
||||||
fileSystem.CreateDirectory(SYSTEM_DIR);
|
fileSystem.CreateDirectory(SYSTEM_DIR);
|
||||||
|
|
||||||
// Create the system.log file in the system directory
|
// Create system log file if it doesn't exist
|
||||||
if (!File.Exists($"{SYSTEM_DIR}{LOG_FILE}"))
|
if (!File.Exists($"{SYSTEM_DIR}{LOG_FILE}"))
|
||||||
fileSystem.CreateFile($"{SYSTEM_DIR}{LOG_FILE}");
|
fileSystem.CreateFile($"{SYSTEM_DIR}{LOG_FILE}");
|
||||||
|
|
||||||
Console.WriteLine(createSysFiles);
|
// Create sysinfo.txt file if it doesn't exist
|
||||||
File.AppendAllText(LOG_FILE, createSysFiles);
|
|
||||||
|
|
||||||
// Create the sysinfo.txt file in the system directory
|
|
||||||
if (!File.Exists($"{SYSTEM_DIR}{sysInfoFile}"))
|
if (!File.Exists($"{SYSTEM_DIR}{sysInfoFile}"))
|
||||||
fileSystem.CreateFile($"{SYSTEM_DIR}{sysInfoFile}");
|
fileSystem.CreateFile($"{SYSTEM_DIR}{sysInfoFile}");
|
||||||
|
|
||||||
Console.WriteLine(setSysPref);
|
// Write system name, version, and build number to sysinfo.txt file
|
||||||
|
|
||||||
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})");
|
File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{SysMeta.NAME} v{SysMeta.VERSION} ({SysMeta.BuildNumber})");
|
||||||
|
|
||||||
Console.WriteLine(fsSuccess);
|
// Set IsFSEnabled property of SysMeta class to true
|
||||||
File.AppendAllText(LOG_FILE, fsSuccess);
|
|
||||||
|
|
||||||
// Set the IsFSActive property of the SysMeta class to true
|
|
||||||
SysMeta.IsFSEnabled = true;
|
SysMeta.IsFSEnabled = true;
|
||||||
|
|
||||||
// Read the contents of the sysinfo.txt file and print it to the console
|
// Read contents of sysinfo.txt file and print to console
|
||||||
var systemInfo = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
var systemInfo = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
||||||
|
|
||||||
Console.WriteLine(systemInfo);
|
Console.WriteLine(systemInfo);
|
||||||
}
|
}
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
// If an exception is caught, print an error message indicating that the file system failed to load
|
// Print error message if an exception is caught
|
||||||
Console.WriteLine($"{err.Message}{Environment.NewLine}Warning: Error messages will not logged.");
|
Console.WriteLine($"{err.Message}{Environment.NewLine}Warning: Error messages will not logged.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new directory at the specified path
|
/// Creates a new directory at the specified path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
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