Skip to content

Commit

Permalink
Merge pull request #143 from SvenMarcus/master
Browse files Browse the repository at this point in the history
Run tests on Windows and Ubuntu with Github Actions
  • Loading branch information
gruenwaldlk authored Feb 15, 2021
2 parents 099c7ea + c992bc6 commit a3e6504
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 68 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/dotnet-core-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ on:
branches: [ master ]

jobs:

build:
build_windows:

strategy:
matrix:
Expand Down Expand Up @@ -85,4 +84,34 @@ jobs:
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}


build_ubuntu:
runs-on: ubuntu-latest

strategy:
matrix:
configuration: [Debug, Release]

env:
Solution_Name: eawx-build.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: eawx-build-test/eawx-build-test.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- name: Install zlib
run: sudo apt-get install -y zlib1g

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: 3.1.101

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test
4 changes: 2 additions & 2 deletions eawx-build-test/EawXBuildApplicationLuaAcceptanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void GivenConfig_With_OneProject_OneJob_And_CopyTask__WhenRunning__Should
Assert.IsTrue(actual);
}

[TestMethod]
public void GivenConfig_With_OneProject_OneJob_And_RunProcessTask__WhenRunning__ShouldRunProcess() {
[PlatformSpecificTestMethod("Linux", "OSX")]
public void GivenUnixLikeSystem_And_Config_With_OneProject_OneJob_And_RunProcessTask__WhenRunning__ShouldRunProcess() {
const string config = @"
local proj = project('pid0')
local job = proj:add_job('My-Job')
Expand Down
8 changes: 4 additions & 4 deletions eawx-build-test/EawXBuildApplicationXmlAcceptanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class EawXBuildXmlApplicationTest {

[TestInitialize]
public void SetUp() {
_services = ConfigureServices(_fileSystem);
_services = ConfigureServices();
}

[TestCleanup]
Expand Down Expand Up @@ -91,8 +91,8 @@ public void WhenRunningWith_OneProject_OneJob_And_CopyTask__ShouldCopyFileToTarg
Assert.IsTrue(actual);
}

[TestMethod]
public void WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgram() {
[PlatformSpecificTestMethod("Linux", "OSX")]
public void GivenUnixLikeSystem__WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgram() {
var options = new RunOptions {
BackendXml = true,
ConfigPath = "eaw-ci.xml",
Expand All @@ -112,7 +112,7 @@ public void WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgr
Assert.AreEqual("Hello World", actual);
}

private static ServiceCollection ConfigureServices(IFileSystem fileSystem, LogLevel logLevel = LogLevel.None) {
private static ServiceCollection ConfigureServices(LogLevel logLevel = LogLevel.None) {
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddConsole());
services.Configure<LoggerFilterOptions>(options =>
Expand Down
28 changes: 8 additions & 20 deletions eawx-build-test/Native/FileLinkerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,77 +34,65 @@ public void TearDown() {
Assert.IsFalse(_fileSystem.File.Exists(GetPlatformTargetPath()));
}

[TestMethod]
[PlatformSpecificTestMethod("OSX")]
public void GivenRunningMacOS__WhenLinkingFileWithUnixStylePath__FileShouldExist() {
if (!TestUtility.IsMacOS()) Assert.Inconclusive();

var sut = new MacOSFileLinker();

sut.CreateLink(UnixFilePath, UnixLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath));
}

[TestMethod]
[PlatformSpecificTestMethod("OSX")]
public void GivenRunningMacOS__WhenLinkingFileWithWinStylePath__FileShouldExist() {
if (!TestUtility.IsMacOS()) Assert.Inconclusive();

var sut = new MacOSFileLinker();

sut.CreateLink(WinFilePath, WinLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath));
}

[TestMethod]
[PlatformSpecificTestMethod("Windows")]
public void GivenRunningWindows__WhenLinkingFileWithUnixStylePath__FileShouldExist() {
if (!TestUtility.IsWindows()) Assert.Inconclusive();

var sut = new WinFileLinker();

sut.CreateLink(UnixFilePath, UnixLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(WinLinkedFilePath));
}

[TestMethod]
[PlatformSpecificTestMethod("Windows")]
public void GivenRunningWindows__WhenLinkingFileWithWinStylePath__FileShouldExist() {
if (!TestUtility.IsWindows()) Assert.Inconclusive();

var sut = new WinFileLinker();

sut.CreateLink(WinFilePath, WinLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(WinLinkedFilePath));
}

[TestMethod]
[PlatformSpecificTestMethod("Linux")]
public void GivenRunningLinux__WhenLinkingFileWithUnixStylePath__FileShouldExist() {
if (!TestUtility.IsLinux()) Assert.Inconclusive();

var sut = new LinuxFileLinker();

sut.CreateLink(UnixFilePath, UnixLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath));
}

[TestMethod]
[PlatformSpecificTestMethod("Linux")]
public void GivenRunningLinux__WhenLinkingFileWithWinStylePath__FileShouldExist() {
if (!TestUtility.IsLinux()) Assert.Inconclusive();

var sut = new LinuxFileLinker();

sut.CreateLink(WinFilePath, WinLinkedFilePath);

Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath));
}

private string GetPlatformSourcePath() {
private static string GetPlatformSourcePath() {
return TestUtility.IsWindows() ? WinFilePath : UnixFilePath;
}

private string GetPlatformTargetPath() {
private static string GetPlatformTargetPath() {
return TestUtility.IsWindows() ? WinLinkedFilePath : UnixLinkedFilePath;
}
}
Expand Down
23 changes: 6 additions & 17 deletions eawx-build-test/Services/IO/IOServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void SetUp() {
TestUtility.GetConfiguredMockFileSystem(out _fileSystem, out _assertions);
}

[TestMethod]
[PlatformSpecificTestMethod("Windows")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("C:/data/test/path", ".dat", true)]
[DataRow("C:/data/test/path", ".xml", false)]
Expand All @@ -25,16 +25,14 @@ public void SetUp() {
[DataRow("C:/data/path", ".dat", false)]
public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__WIN(string absoluteDirectoryPath,
string fileExtension, bool expected) {
if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows.");

const string fileName = "test";
var svc = new IOService(_fileSystem);
Assert.AreEqual(expected, svc.IsValidPath(
_fileSystem.Path.Combine(absoluteDirectoryPath, fileName + fileExtension),
string.Empty, fileExtension));
}

[TestMethod]
[PlatformSpecificTestMethod("Linux", "OSX")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("/mnt/c/data/test/path", ".dat", true)]
[DataRow("/mnt/c/data/test/path", ".xml", false)]
Expand All @@ -44,16 +42,14 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__WI
[DataRow("/mnt/c/data/path", ".dat", false)]
public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__UNX(string absoluteDirectoryPath,
string fileExtension, bool expected) {
if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix.");

const string fileName = "test";
var svc = new IOService(_fileSystem);
Assert.AreEqual(expected, svc.IsValidPath(
_fileSystem.Path.Combine(absoluteDirectoryPath, fileName + fileExtension),
string.Empty, fileExtension));
}

[TestMethod]
[PlatformSpecificTestMethod("Windows")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("data/test/path", ".dat")]
[DataRow("/test/path", ".xml")]
Expand All @@ -63,16 +59,14 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__UN
[DataRow("data/path", ".dat")]
public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_WIN(string absoluteDirectoryPath,
string fileExtension) {
if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows.");

const string fileName = "test";
var svc = new IOService(_fileSystem);
Assert.IsFalse(svc.IsValidPath(
_fileSystem.Path.Combine(absoluteDirectoryPath, fileName + fileExtension),
string.Empty, fileExtension));
}

[TestMethod]
[PlatformSpecificTestMethod("Linux", "OSX")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("data/test/path", ".dat")]
[DataRow("/test/path", ".xml")]
Expand All @@ -83,41 +77,36 @@ public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_WIN
public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_UNX(string absoluteDirectoryPath,
string fileExtension) {
var svc = new IOService(_fileSystem);
if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix.");

const string fileName = "test";
Assert.IsFalse(svc.IsValidPath(
_fileSystem.Path.Combine(absoluteDirectoryPath, fileName + fileExtension),
string.Empty, fileExtension));
}

[TestMethod]
[PlatformSpecificTestMethod("Linux", "OSX")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("test/path", "/mnt/c/data", ".dat", true)]
[DataRow("../../path", "/mnt/c/data/test/path", ".xml", true)]
[DataRow("../../path", "/mnt/c/data/test/path", ".dat", false)]
[DataRow("../path", "/mnt/c/data/test/path", ".xml", false)]
public void GivenRelativePathToFile__IsValidPath__IsExpected_UNX(string relativeDirectoryPath, string basePath,
string fileExtension, bool expected) {
if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix.");

const string fileName = "test";
var svc = new IOService(_fileSystem);
Assert.AreEqual(expected, svc.IsValidPath(
_fileSystem.Path.Combine(relativeDirectoryPath, fileName + fileExtension),
basePath, fileExtension));
}

[TestMethod]
[PlatformSpecificTestMethod("Windows")]
[TestCategory(TestUtility.TEST_TYPE_UTILITY)]
[DataRow("test/path", "C:/data", ".dat", true)]
[DataRow("../../path", "C:/data/test/path", ".xml", true)]
[DataRow("../../path", "C:/data/test/path", ".dat", false)]
[DataRow("../path", "C:/data/test/path", ".xml", false)]
public void GivenRelativePathToFile__IsValidPath__IsExpected_WIN(string relativeDirectoryPath, string basePath,
string fileExtension, bool expected) {
if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows.");

const string fileName = "test";
var svc = new IOService(_fileSystem);
Assert.AreEqual(expected, svc.IsValidPath(
Expand Down
53 changes: 50 additions & 3 deletions eawx-build-test/Services/Process/ProcessRunnerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace EawXBuildTest.Services.Process {
[TestClass]
public class ProcessRunnerTest {
[TestMethod]

[PlatformSpecificTestMethod("Linux", "OSX")]
public void GivenEcho__WhenStarting__ShouldExitWithCodeZero() {
var sut = new ProcessRunner();

Expand All @@ -19,7 +20,7 @@ public void GivenEcho__WhenStarting__ShouldExitWithCodeZero() {
Assert.AreEqual(0, actual);
}

[TestMethod]
[PlatformSpecificTestMethod("Linux", "OSX")]
public void GivenEchoWithArgs__WhenStarting__ShouldPrintOutArgs() {
var stringBuilder = new StringBuilder();
Console.SetOut(new StringWriter(stringBuilder));
Expand All @@ -34,7 +35,7 @@ public void GivenEchoWithArgs__WhenStarting__ShouldPrintOutArgs() {
Assert.AreEqual(expected, actual);
}

[TestMethod]
[PlatformSpecificTestMethod("Linux", "OSX")]
public void GivenProcessStartInfoForEcho__WhenStarting__ShouldPrintOutArgs() {
var stringBuilder = new StringBuilder();
Console.SetOut(new StringWriter(stringBuilder));
Expand All @@ -53,5 +54,51 @@ public void GivenProcessStartInfoForEcho__WhenStarting__ShouldPrintOutArgs() {
var actual = stringBuilder.ToString().Trim();
Assert.AreEqual(expected, actual);
}

[PlatformSpecificTestMethod("Windows")]
public void GivenCmdNoCommand__WhenStarting__ShouldExitWithCodeZero() {
var sut = new ProcessRunner();

sut.Start("cmd.exe", "/c");
sut.WaitForExit();

var actual = sut.ExitCode;
Assert.AreEqual(0, actual);
}

[PlatformSpecificTestMethod("Windows")]
public void GivenCmdWithEchoCommandAndArgs__WhenStarting__ShouldPrintOutArgs() {
var stringBuilder = new StringBuilder();
Console.SetOut(new StringWriter(stringBuilder));

var sut = new ProcessRunner();

const string expected = "Hello World";
sut.Start("cmd.exe", "/c echo " + expected);
sut.WaitForExit();

var actual = stringBuilder.ToString().Trim();
Assert.AreEqual(expected, actual);
}

[PlatformSpecificTestMethod("Windows")]
public void GivenProcessStartInfoForCmdWithEcho__WhenStarting__ShouldPrintOutArgs() {
var stringBuilder = new StringBuilder();
Console.SetOut(new StringWriter(stringBuilder));

var sut = new ProcessRunner();

const string expected = "Hello World";
var startInfo = new ProcessStartInfo {
FileName = "cmd.exe",
Arguments = "/c echo " + expected
};

sut.Start(startInfo);
sut.WaitForExit();

var actual = stringBuilder.ToString().Trim();
Assert.AreEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ public void TearDown() {
_itemFolder.Delete(true);
}

[TestMethod]
[TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")]
public async Task GivenWorkshopChangeSet__WhenPublishingToSteam__ItemShouldBeOnWorkshop() {
if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive();

var changeSet = new WorkshopItemChangeSet(_fileSystem) {
Title = Title,
DescriptionFilePath = DescriptionFilePath,
Expand All @@ -75,10 +73,8 @@ public async Task GivenWorkshopChangeSet__WhenPublishingToSteam__ItemShouldBeOnW
await AssertItemMatchesSettings(publishTaskResult);
}

[TestMethod]
[TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")]
public async Task WhenQueryingForItemId__ShouldReturnItemWithId() {
if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive();

_sut.Init(32470);
const ulong fotrWorkshopId = 1976399102;
var workshopItem = await _sut.QueryWorkshopItemByIdAsync(fotrWorkshopId);
Expand Down
Loading

0 comments on commit a3e6504

Please sign in to comment.