diff --git a/scripts/Makefile b/scripts/Makefile index 8b2f8d6e8..0cd2c8179 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -157,7 +157,9 @@ internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun cp -r ../ext-src/pester exec_env/app_base/Modules/Pester cp runps.sh exec_env/app_base -run: $(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll dotnetlibs/Microsoft.PowerShell.Security.dll dotnetlibs/api-ms-win-core-registry-l1-1-0.dll internal-prepare-exec_env +RUN_TARGETS=$(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll dotnetlibs/Microsoft.PowerShell.Security.dll dotnetlibs/api-ms-win-core-registry-l1-1-0.dll + +run: $(RUN_TARGETS) internal-prepare-exec_env # check if corerun is the right one (could be the debug version) if ! diff dotnetlibs/corerun $(MONAD_EXT)/coreclr/Release/corerun; then cp -r $(MONAD_EXT)/coreclr/Release/* dotnetlibs; fi # execute a cmdlet, this will auto-load the utility module and print a, b and c in 3 lines @@ -179,7 +181,7 @@ pester-tests: $(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun dotnetlibs/Microsoft. # execute the pester tests, pester needs a TEMP environment variable to be set cd exec_env/app_base && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=. ./corerun powershell-simple.exe 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester' -test: internal-prepare-exec_env $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) dotnetlibs/corerun +test: $(RUN_TARGETS) internal-prepare-exec_env $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) dotnetlibs/corerun cd exec_env/testrun && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=../app_base ../app_base/corerun xunit.console.netcore.exe ps_test.dll # this is an internal target, it's not intended to be called manually diff --git a/src/ps_test/ps_test.cs b/src/ps_test/ps_test.cs deleted file mode 100644 index d42d7a0e5..000000000 --- a/src/ps_test/ps_test.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -namespace PSTests -{ - public static class TestRunner - { - // TODO: Replace with xUnit test runner - // - Add [Fact] attributes to test - // - Remove static keywords - static void Main() - { - PlatformTests.TestIsLinux(); - PlatformTests.TestHasCom(); - PlatformTests.TestHasAmsi(); - PlatformTests.TestUsesCodeSignedAssemblies(); - PlatformTests.TestHasDriveAutoMounting(); - PlatformTests.TestHasRegistrySupport(); - - PSTypeExtensionsTests.TestIsComObject(); - - PSEnumerableBinderTests.TestIsComObject(); - - SecuritySupportTests.TestScanContent(); - SecuritySupportTests.TestCurrentDomain_ProcessExit(); - SecuritySupportTests.TestCloseSession(); - SecuritySupportTests.TestUninitialize(); - - MshSnapinInfoTests mshSnapinInfoTests = new MshSnapinInfoTests(); - mshSnapinInfoTests.TestReadRegistryInfo(); - mshSnapinInfoTests.TestReadCoreEngineSnapIn(); - - Console.WriteLine("Finished running tests"); - } - } -} diff --git a/src/ps_test/test_Binders.cs b/src/ps_test/test_Binders.cs index 6123f1998..6f5a8f7d1 100644 --- a/src/ps_test/test_Binders.cs +++ b/src/ps_test/test_Binders.cs @@ -6,6 +6,7 @@ namespace PSTests { public static class PSEnumerableBinderTests { + [Fact] public static void TestIsComObject() { // It just needs an arbitrary object diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 6baf895c4..fe2387b43 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -6,31 +6,37 @@ namespace PSTests { public static class PlatformTests { + [Fact] public static void TestIsLinux() { Assert.True(Platform.IsLinux()); } + [Fact] public static void TestHasCom() { Assert.False(Platform.HasCom()); } + [Fact] public static void TestHasAmsi() { Assert.False(Platform.HasAmsi()); } + [Fact] public static void TestUsesCodeSignedAssemblies() { Assert.False(Platform.UsesCodeSignedAssemblies()); } + [Fact] public static void TestHasDriveAutoMounting() { Assert.False(Platform.HasDriveAutoMounting()); } + [Fact] public static void TestHasRegistrySupport() { Assert.False(Platform.HasRegistrySupport()); diff --git a/src/ps_test/test_ExtensionMethods.cs b/src/ps_test/test_ExtensionMethods.cs index b7b7d82ba..e22de8be5 100644 --- a/src/ps_test/test_ExtensionMethods.cs +++ b/src/ps_test/test_ExtensionMethods.cs @@ -6,6 +6,7 @@ namespace PSTests { public static class PSTypeExtensionsTests { + [Fact] public static void TestIsComObject() { // It just needs an arbitrary type diff --git a/src/ps_test/test_MshSnapinInfo.cs b/src/ps_test/test_MshSnapinInfo.cs index 45499dd4a..a283e7995 100644 --- a/src/ps_test/test_MshSnapinInfo.cs +++ b/src/ps_test/test_MshSnapinInfo.cs @@ -8,6 +8,7 @@ namespace PSTests public class MshSnapinInfoTests { // Test that it does not throw an exception + [Fact] public void TestReadRegistryInfo() { Version someVersion = null; @@ -16,6 +17,7 @@ namespace PSTests } // PublicKeyToken is null on Linux + [Fact] public void TestReadCoreEngineSnapIn() { PSSnapInInfo pSSnapInInfo = PSSnapInReader.ReadCoreEngineSnapIn(); diff --git a/src/ps_test/test_SecuritySupport.cs b/src/ps_test/test_SecuritySupport.cs index 88f9606a4..4c3b4b9b1 100644 --- a/src/ps_test/test_SecuritySupport.cs +++ b/src/ps_test/test_SecuritySupport.cs @@ -6,21 +6,25 @@ namespace PSTests { public static class SecuritySupportTests { + [Fact] public static void TestScanContent() { Assert.Equal(AmsiUtils.ScanContent("", ""), AmsiUtils.AmsiNativeMethods.AMSI_RESULT.AMSI_RESULT_NOT_DETECTED); } + [Fact] public static void TestCurrentDomain_ProcessExit() { AmsiUtils.CurrentDomain_ProcessExit(null, EventArgs.Empty); } + [Fact] public static void TestCloseSession() { AmsiUtils.CloseSession(); } + [Fact] public static void TestUninitialize() { AmsiUtils.Uninitialize();