Refactor unit tests

Splits unit tests into multiple files and a mock test runner (to be
replaced with the xUnit runner when it becomes available).
This commit is contained in:
Andrew Schwartzmeyer 2015-06-11 13:40:07 -07:00
parent 3ab9a20121
commit d9a0c8270f
4 changed files with 34 additions and 28 deletions

View file

@ -112,8 +112,15 @@ dotnetlibs/xunit.assert.dll: $(MONAD_EXT)/xunit/xunit.assert.dll
dotnetlibs/xunit.console.exe: $(MONAD_EXT)/xunit/xunit.console.netcore.exe
cp -f $^ $@
dotnetlibs/ps_test.exe: ../src/ps_test/ps_test.cs dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) dotnetlibs/xunit.core.dll dotnetlibs/xunit.assert.dll
$(CSC) -out:$@ -noconfig -nostdlib -target:exe -r:dotnetlibs/System.Management.Automation.dll -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) -r:dotnetlibs/xunit.core.dll -r:dotnetlibs/xunit.assert.dll ${COREREF} ../src/ps_test/ps_test.cs
TEST_FOLDER=../src/ps_test
TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_CorePsPlatform.cs)
TEST_DLLS=$(addprefix dotnetlibs/, $(notdir $(TEST_SRCS:.cs=.dll)))
dotnetlibs/%.dll: $(TEST_FOLDER)/%.cs dotnetlibs/xunit.core.dll dotnetlibs/xunit.assert.dll dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET)
$(CSC) -out:$@ -noconfig -nostdlib -target:library -r:dotnetlibs/System.Management.Automation.dll -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) -r:dotnetlibs/xunit.core.dll -r:dotnetlibs/xunit.assert.dll ${COREREF} $<
dotnetlibs/ps_test.exe: $(TEST_FOLDER)/ps_test.cs $(TEST_DLLS) dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) dotnetlibs/xunit.core.dll dotnetlibs/xunit.assert.dll
$(CSC) -out:$@ -noconfig -nostdlib -target:exe $(addprefix -r:, $(TEST_DLLS)) -r:dotnetlibs/System.Management.Automation.dll -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) -r:dotnetlibs/xunit.core.dll -r:dotnetlibs/xunit.assert.dll ${COREREF} $<
run-test: dotnetlibs/ps_test.exe dotnetlibs/corerun
cd dotnetlibs && LD_LIBRARY_PATH=. ./corerun ps_test.exe

View file

@ -7,7 +7,7 @@ using System.Reflection;
[assembly:InternalsVisibleTo("Microsoft.PowerShell.Security")]
[assembly:InternalsVisibleTo("Microsoft.PowerShell.CoreCLR.AssemblyLoadContext")]
//[assembly:InternalsVisibleTo("ps_hello_world")]
[assembly:InternalsVisibleTo("ps_test")]
[assembly:InternalsVisibleTo("test_CorePsPlatform")]
//

View file

@ -1,30 +1,16 @@
using Xunit;
using System;
namespace PSTests
{
public class BlahTests
{
// [Fact]
public static void simpleTest()
{
Assert.Equal(1,1);
}
public static void testPlatform()
{
Assert.Equal(System.Management.Automation.Platform.IsLinux(),true);
// UserName not yet implemented
// Assert.Equal(System.Management.Automation.Platform.UserName,"peter2");
}
static void Main(string[] args)
{
simpleTest();
testPlatform();
Console.WriteLine("finished running tests");
}
}
public static class TestRunner
{
// TODO: Replace with xUnit test runner
// - Add [Fact] attributes to test
// - Remove static keywords
static void Main()
{
PlatformTests.testIsLinux();
Console.WriteLine("Finished running tests");
}
}
}

View file

@ -0,0 +1,13 @@
using Xunit;
using System;
namespace PSTests
{
public static class PlatformTests
{
public static void testIsLinux()
{
Assert.Equal(System.Management.Automation.Platform.IsLinux(), true);
}
}
}