From 4ff63410342634e9153c24b79d7f78d70a32a1f6 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 1 Sep 2015 16:57:16 -0700 Subject: [PATCH 01/16] implemented xunit tests for testing isHardLink using a fileSystem object --- src/ps_test/test_CorePsPlatform.cs | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 57e58bc32..b761c234b 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -1,5 +1,6 @@ using Xunit; using System; +using System.IO; using System.Diagnostics; using System.Management.Automation; @@ -90,5 +91,38 @@ namespace PSTests } + + [Fact] + public static void TestIsHardLink() + { + // a file that should exist on every *nix distro + + string path = @"/tmp/MyTest"; + if (!File.Exists(path)) + { + File.Create(path); + } + + // Create a file to write to using StreamWriter. + // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); + MemoryStream stream = new MemoryStream(byteArray); + + using (StreamWriter sw = new StreamWriter(stream)) + { + sw.Write("Hello"); + } + + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.True(Platform.NonWindowsIsHardLink(fd)); + } + + [Fact] + public static void TestIsHardLinkFailsWithDirectory() + { + + } + } } From 73b1a714208e03eacba185dda2bfc25c33d50d7b Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 1 Sep 2015 16:58:16 -0700 Subject: [PATCH 02/16] bringing implementation code up-to-date with the test code --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index d541b0734..01ff8a3f7 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit d541b073435e55fd96771697e5549cc9a188fa54 +Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 From 080c734dfb93c0aa2cfd3b765b26d1affb245137 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 11:02:09 -0700 Subject: [PATCH 03/16] added fail under directory as input unit test --- src/ps_test/test_CorePsPlatform.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index b761c234b..bc62134ca 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -93,7 +93,7 @@ namespace PSTests } [Fact] - public static void TestIsHardLink() + public static void TestIsHardLinkWithFileSystemInfo() { // a file that should exist on every *nix distro @@ -102,7 +102,6 @@ namespace PSTests { File.Create(path); } - // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); @@ -119,9 +118,20 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkFailsWithDirectory() + public static void TestIsHardLinkFailsWithDirectoryWithFileSystemInfo() { - + // A folder that should exist on every *nix system + string path = @"/tmp"; + + // Create a file to write to using StreamWriter. + // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); + MemoryStream stream = new MemoryStream(byteArray); + + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.False(Platform.NonWindowsIsHardLink(fd)); + } } From 9b02eea58dca19af87ac117b3840ab27f4a01157 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 11:15:31 -0700 Subject: [PATCH 04/16] added unit test for additional failure cases and removed unneeded code from existing unit tests --- src/ps_test/test_CorePsPlatform.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index bc62134ca..a8bf60eb9 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -102,6 +102,7 @@ namespace PSTests { File.Create(path); } + // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); @@ -123,16 +124,23 @@ namespace PSTests // A folder that should exist on every *nix system string path = @"/tmp"; - // Create a file to write to using StreamWriter. - // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. - byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); - MemoryStream stream = new MemoryStream(byteArray); + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.False(Platform.NonWindowsIsHardLink(fd)); + } + + [Fact] + public static void TestIsHardLinkFailsWithNonexistantFileWithFileSystemInfo() + { + // A file that should *never* exist on a test machine: + string path = @"/tmp/ThisFileShouldNotExistOnTestMachines"; + + // If the file exists, then there's a larger issue that needs to be looked at + Assert.False(File.Exists(path)); // Convert `path` string to FileSystemInfo data type. And now, it should return true FileSystemInfo fd = new FileInfo(path); Assert.False(Platform.NonWindowsIsHardLink(fd)); - } - } } From 74f0a893c1dda04f2cccdcdb52968e19525baeb7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 2 Sep 2015 15:17:35 -0700 Subject: [PATCH 05/16] Repin monad --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 01ff8a3f7..d0697c432 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 +Subproject commit d0697c432c1d678e59af3ebd6320e5bc3a432b2f From aa45feb3856867b986c15afdcce561b02f9a14f0 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 16:15:52 -0700 Subject: [PATCH 06/16] Added test suite for Test-Path cmdlet --- src/pester-tests/Test-Test-Path.Tests.ps1 | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/pester-tests/Test-Test-Path.Tests.ps1 diff --git a/src/pester-tests/Test-Test-Path.Tests.ps1 b/src/pester-tests/Test-Test-Path.Tests.ps1 new file mode 100644 index 000000000..144442fa1 --- /dev/null +++ b/src/pester-tests/Test-Test-Path.Tests.ps1 @@ -0,0 +1,106 @@ +Describe "Test-Test-Path" { + $testdirectory = "/usr/bin" + $testfilename = "vi" # use /usr/bin/vi since that's bundled with all linux + $testfile = $testdirectory + "/" + $testfilename + It "Should be called on an existing path without error" { + { Test-Path $testdirectory } | Should Not Throw + { Test-Path -Path $testdirectory } | Should Not Throw + { Test-Path -LiteralPath $testdirectory } | Should Not Throw + } + + It "Should allow piping objects to it" { + { $testdirectory | Test-Path } | Should Not Throw + } + + It "Should return a boolean data type" { + { Test-Path -Path $testdirectory } | Should Be ($true -or $false) + } + + It "Should be called on a nonexistant path without error" { + { Test-Path -Path "aNonexistant/path/that/should/error" } | Should Not Throw + } + + It "Should return false for a nonexistant path" { + Test-Path -Path "aNonexistant/path/that/should/error" | Should Be $false + } + + It "Should return true for an existing path" { + Test-Path -Path $testdirectory | Should Be $true + } + + It "Should be able to accept a regular expression" { + { Test-Path -Path "/u*" } | Should Not Throw + } + + It "Should be able to return the correct result when a regular expression is used" { + Test-Path -Path "/u*" | Should Be $true + + Test-Path -Path "/aoeu*" | Should Be $false + } + + It "Should return false when the Leaf pathtype is used on a directory" { + Test-Path -Path $testdirectory -PathType Leaf | Should Be $false + } + + It "Should return true when the Leaf pathtype is used on an existing endpoint" { + Test-Path -Path $testfile -PathType Leaf | Should Be $true + } + + It "Should return false when the Leaf pathtype is used on a nonexistant file" { + Test-Path -Path "aoeu" -PathType Leaf | Should Be $false + } + + It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" { + Test-Path -Path $testfile -Type Leaf | Should Be $true + } + + It "Should be able to search multiple regular expressions using the include switch" { + Test-Path -Path "/usr/bin/*" -Include vi* | Should Be $true + } + + It "Should be able to exclude a regular expression using the exclude switch" { + Test-Path -Path "/usr/bin/" -Exclude vi* | Should Be $true + } + + It "Should be able to exclude multiple regular expressions using the exclude switch" { + # tests whether there's any files in the /usr directory that don't start with 'd' or 'g' + Test-Path -Path "/usr" -Exclude d*, g* | Should Be $true + } + + It "Should return true if the syntax of the path is correct when using the IsValid switch" { + Test-Path -Path /this/is/a/valid/path -IsValid | Should Be $true + } + + It "Should return false if the syntax of the path is incorrect when using the IsValid switch" { + Test-Path -Path C:/usr/bin -IsValid | Should Be $false + } + + It "Should return true on paths containing spaces when the path is surrounded in quotes" { + Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true + } + + It "Should throw on paths containing spaces when the path is not surrounded in quotes" { + { Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw + } + + It "Should return true if a directory leads or trails with a space when surrounded by quotes" { + Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true + } + + It "Should return true on a valid path when the LiteralPath switch is used" { + Test-Path -LiteralPath "/usr/bin" | Should Be $true + } + + It "Should return false if regular expressions are used with the LiteralPath switch" { + Test-Path -LiteralPath /*sr/bin | Should Be $false + } + + It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" { + Test-Path -PSPath /*sr/bin | Should Be $false + } + + It "Should return true if used on components other than filesystem objects" { + Test-Path Alias:\gci | Should Be $true + Test-Path Env:\HOSTNAME | Should Be $true + } +} From 84d58714fc2afdb3bf3c2475887f38206ecc0c11 Mon Sep 17 00:00:00 2001 From: Peter Honeder Date: Thu, 3 Sep 2015 21:43:17 +0200 Subject: [PATCH 07/16] added a simple test that creates a full PS Runspace and executes a script --- scripts/Makefile | 2 +- scripts/runps-test.sh | 7 ++++++ src/ps_test/test_Runspace.cs | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 scripts/runps-test.sh create mode 100644 src/ps_test/test_Runspace.cs diff --git a/scripts/Makefile b/scripts/Makefile index 174a68bd0..1bd25a099 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -194,7 +194,7 @@ native-tests: dotnetlibs/monad_native xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) # execute the xUnit runner, with XML output - cd exec_env/app_base && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=../coreclr:. ../coreclr/corerun xunit.console.netcore.exe ps_test.dll -xml ../../xunittests.xml + exec_env/app_base/runps-test.sh ps_test.dll -xml ../../xunittests.xml pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr # execute the Pester tests, which needs a TEMP environment variable to be set diff --git a/scripts/runps-test.sh b/scripts/runps-test.sh new file mode 100755 index 000000000..5196f708b --- /dev/null +++ b/scripts/runps-test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +CWD=$(pwd) +SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +cd "$SCRIPTDIR" +PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa xunit.console.netcore.exe xunit.console.netcore.exe "$@" diff --git a/src/ps_test/test_Runspace.cs b/src/ps_test/test_Runspace.cs new file mode 100644 index 000000000..f9b4745eb --- /dev/null +++ b/src/ps_test/test_Runspace.cs @@ -0,0 +1,48 @@ +using Xunit; +using System; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +namespace PSTests +{ + public static class RunspaceTests + { + [Fact] + public static void TestMethod() + { + InitialSessionState iss = InitialSessionState.CreateDefault2(); + + // NOTE: instantiate custom host myHost for the next line to capture stdout and stderr output + // in addition to just the PSObjects + using (Runspace rs = RunspaceFactory.CreateRunspace(/*myHost,*/iss)) + { + rs.Open(); + using (PowerShell ps = PowerShell.Create()) + { + ps.Runspace = rs; + + string script = "get-process | select-object -first 3"; + ps.AddScript(script); + + // IMPORTANT NOTE: do not call AddCommand("out-host") here or + // MergeMyResults, otherwise Invoke will not return any objects + + var results = ps.Invoke(); + + // check that there are 3 captured objects + int objCount = 0; + foreach (var result in results) + { + // this is how an object would be captured here and looked at, + // each result is a PSObject with the data from the pipeline + ++objCount; + Assert.NotNull(result); + } + Assert.Equal(3,objCount); + ps.Dispose(); + } + } + } + } +} + From 562a9bb35b3467af8803812806ea3a019165ea7b Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 3 Sep 2015 14:31:46 -0700 Subject: [PATCH 08/16] Add Security.dll reference for Commands.Management.dll While enabling previously disabled code in `cimConverter.cs`, it was revealed that `Microsoft.PowerShell.Commands.Management.dll` has a dependency on `Microsoft.PowerShell.Security.dll` for the type `SecurityDescriptorCommandsBase`. --- scripts/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 174a68bd0..7882c6457 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -72,13 +72,13 @@ dotnetlibs/Microsoft.Management.Infrastructure.dll: ${MAN_INFRA_SRCS} dotnetlibs # Commands -dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: ${COMMANDS_MANAGEMENT_SRCS} dotnetlibs/System.Management.Automation.dll ${COMMANDS_MANAGEMENT_RES_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(MI_ASSEMBLY) - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${COMMANDS_MANAGEMENT_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(COMMANDS_MANAGEMENT_RES_REF) $(MI_REF) +dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: ${COMMANDS_MANAGEMENT_SRCS} dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll ${COMMANDS_MANAGEMENT_RES_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(MI_ASSEMBLY) + $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${COMMANDS_MANAGEMENT_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(COMMANDS_MANAGEMENT_RES_REF) $(MI_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: ${COMMANDS_UTILITY_SRCS} dotnetlibs/System.Management.Automation.dll ${COMMANDS_UTILITY_RES_SRCS} ${COMMANDS_UTILITY_RES_CS_SRCS} $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${COMMANDS_UTILITY_SRCS} ${COMMANDS_UTILITY_RES_CS_SRCS} $(COMMANDS_UTILITY_RES_REF) -dotnetlibs/Microsoft.PowerShell.Security.dll: ${SECURITY_SRCS} dotnetlibs/System.Management.Automation.dll ${SECURITY_RES_SRCS} ${SECURITY_RES_CS_SRCS} +dotnetlibs/Microsoft.PowerShell.Security.dll: ${SECURITY_SRCS} ${SECURITY_RES_SRCS} ${SECURITY_RES_CS_SRCS} $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${SECURITY_SRCS} ${SECURITY_RES_CS_SRCS} $(SECURITY_RES_REF) # assembly load context From f163808eac8c6dfee5be7fd42a02962225aef050 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 3 Sep 2015 14:55:21 -0700 Subject: [PATCH 09/16] Swap {} for () in Makefile Parentheses are more portable. There was an inconsistent mix of parentheses and curly braces. --- scripts/Makefile | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 3e4d51e14..00d0874c3 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -41,16 +41,16 @@ MI_REF_ASSEMBLY=-r:$(MONAD_EXT)/PS/PS_refs_modil/microsoft.management.infrastruc MI_ASSEMBLY=dotnetlibs/Microsoft.Management.Infrastructure.dll MI_REF=-r:$(MI_ASSEMBLY) -PRODUCT_BASE_REFS=${COREREF} -PRODUCT_MI_REFS=${COREREF} ${MI_NATIVE_REF} -PRODUCT_PS_REFS=${COREREF} ${MI_REF} -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) -PRODUCT_COMMANDS_REFS=${COREREF} -r:dotnetlibs/System.Management.Automation.dll +PRODUCT_BASE_REFS=$(COREREF) +PRODUCT_MI_REFS=$(COREREF) $(MI_NATIVE_REF) +PRODUCT_PS_REFS=$(COREREF) $(MI_REF) -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) +PRODUCT_COMMANDS_REFS=$(COREREF) -r:dotnetlibs/System.Management.Automation.dll MCSOPTS_BASE=-unsafe -nostdlib -noconfig -define:CORECLR -define:_CORECLR -MCSOPTS_MI=${MCSOPTS_BASE} -target:library -MCSOPTS_LIB=${MCSOPTS_BASE} -target:library -MCSOPTS_PS=${STRING_RESOURCES_ORIG} ${MCSOPTS_BASE} -target:library -SRCS_ALL=${STRING_RESOURCES} ${SRCS} +MCSOPTS_MI=$(MCSOPTS_BASE) -target:library +MCSOPTS_LIB=$(MCSOPTS_BASE) -target:library +MCSOPTS_PS=$(STRING_RESOURCES_ORIG) $(MCSOPTS_BASE) -target:library +SRCS_ALL=$(STRING_RESOURCES) $(SRCS) # compilers # - Roslyn's csc is used for all the PS code @@ -63,28 +63,28 @@ RUN_TARGETS=$(POWERSHELL_RUN_TARGETS) dotnetlibs/Microsoft.PowerShell.Commands.M all: dotnetlibs/System.Management.Automation.dll $(RUN_TARGETS) dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) # this is the build rule for SMA.dll -dotnetlibs/System.Management.Automation.dll: ${SYS_AUTO_SRCS} dotnetlibs/Microsoft.Management.Infrastructure.dll ../src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(PLATFORM_SRCS) ${SYS_AUTO_RES_SRCS} ${SYS_AUTO_RES_CS_SRCS} - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_PS_REFS} ${SYS_AUTO_SRCS} ${SYS_AUTO_RES_REF} ${SYS_AUTO_RES_CS_SRCS} $(PLATFORM_SRCS) ../src/assembly-info/System.Management.Automation.assembly-info.cs +dotnetlibs/System.Management.Automation.dll: $(SYS_AUTO_SRCS) dotnetlibs/Microsoft.Management.Infrastructure.dll ../src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(PLATFORM_SRCS) $(SYS_AUTO_RES_SRCS) $(SYS_AUTO_RES_CS_SRCS) + $(CSC) -out:$@ $(MCSOPTS_LIB) $(PRODUCT_PS_REFS) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_REF) $(SYS_AUTO_RES_CS_SRCS) $(PLATFORM_SRCS) ../src/assembly-info/System.Management.Automation.assembly-info.cs # this is the build rule for MMI.dll -dotnetlibs/Microsoft.Management.Infrastructure.dll: ${MAN_INFRA_SRCS} dotnetlibs/Microsoft.Management.Infrastructure.Native.dll ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) +dotnetlibs/Microsoft.Management.Infrastructure.dll: $(MAN_INFRA_SRCS) dotnetlibs/Microsoft.Management.Infrastructure.Native.dll ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) $(CSC) -out:$@ $(MCSOPTS_MI) $(PRODUCT_MI_REFS) $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_REF) $(MAN_INFRA_RES_CS_SRCS) ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs # Commands -dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: ${COMMANDS_MANAGEMENT_SRCS} dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll ${COMMANDS_MANAGEMENT_RES_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(MI_ASSEMBLY) - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${COMMANDS_MANAGEMENT_SRCS} ${COMMANDS_MANAGEMENT_RES_CS_SRCS} $(COMMANDS_MANAGEMENT_RES_REF) $(MI_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll +dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: $(COMMANDS_MANAGEMENT_SRCS) dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll $(COMMANDS_MANAGEMENT_RES_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(MI_ASSEMBLY) + $(CSC) -out:$@ $(MCSOPTS_LIB) $(PRODUCT_COMMANDS_REFS) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(COMMANDS_MANAGEMENT_RES_REF) $(MI_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll -dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: ${COMMANDS_UTILITY_SRCS} dotnetlibs/System.Management.Automation.dll ${COMMANDS_UTILITY_RES_SRCS} ${COMMANDS_UTILITY_RES_CS_SRCS} - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${COMMANDS_UTILITY_SRCS} ${COMMANDS_UTILITY_RES_CS_SRCS} $(COMMANDS_UTILITY_RES_REF) +dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: $(COMMANDS_UTILITY_SRCS) dotnetlibs/System.Management.Automation.dll $(COMMANDS_UTILITY_RES_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) + $(CSC) -out:$@ $(MCSOPTS_LIB) $(PRODUCT_COMMANDS_REFS) $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) $(COMMANDS_UTILITY_RES_REF) -dotnetlibs/Microsoft.PowerShell.Security.dll: ${SECURITY_SRCS} ${SECURITY_RES_SRCS} ${SECURITY_RES_CS_SRCS} - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_COMMANDS_REFS} ${SECURITY_SRCS} ${SECURITY_RES_CS_SRCS} $(SECURITY_RES_REF) +dotnetlibs/Microsoft.PowerShell.Security.dll: $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) + $(CSC) -out:$@ $(MCSOPTS_LIB) $(PRODUCT_COMMANDS_REFS) $(SECURITY_SRCS) $(SECURITY_RES_CS_SRCS) $(SECURITY_RES_REF) # assembly load context dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): $(ASSEMBLY_LOAD_CONTEXT_SRCS) - $(CSC) -out:$@ ${MCSOPTS_LIB} ${PRODUCT_BASE_REFS} $(ASSEMBLY_LOAD_CONTEXT_SRCS) + $(CSC) -out:$@ $(MCSOPTS_LIB) $(PRODUCT_BASE_REFS) $(ASSEMBLY_LOAD_CONTEXT_SRCS) # this will copy whatever the first version of the dll in the globber is buildtemp/System.Reflection.Metadata.dll: buildtemp/System.Reflection.Metadata.*/lib/portable-net45+win8/System.Reflection.Metadata.dll @@ -101,7 +101,7 @@ dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: ../src/stubs/Microsof MPATH=/usr/lib/mono/4.5/Facades buildtemp/TypeCatalogGen.exe: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs buildtemp/System.Reflection.Metadata.dll buildtemp/System.Collections.Immutable.dll - $(MCS) -out:$@ -target:exe ${NUGETREF} -pkg:dotnet -r:${MPATH}/System.Runtime.dll -r:${MPATH}/System.Reflection.Primitives.dll -r:${MPATH}/System.IO.dll $< + $(MCS) -out:$@ -target:exe $(NUGETREF) -pkg:dotnet -r:$(MPATH)/System.Runtime.dll -r:$(MPATH)/System.Reflection.Primitives.dll -r:$(MPATH)/System.IO.dll $< # generate the Core PS type catalog # this comes from: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/makefile.inc From f70f004238eff0612cee175001fb80b6b27eca02 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 3 Sep 2015 15:23:16 -0700 Subject: [PATCH 10/16] Missed a pair --- scripts/tests.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests.mk b/scripts/tests.mk index 8a7c312a2..4f9963828 100644 --- a/scripts/tests.mk +++ b/scripts/tests.mk @@ -6,4 +6,4 @@ $(TESTRUN_FOLDER)/xunit%: $(MONAD_EXT)/xunit/xunit% cp -f $^ $@ $(TESTRUN_FOLDER)/ps_test.dll: $(TEST_SRCS) $(addprefix $(TESTRUN_FOLDER)/, xunit.core.dll xunit.assert.dll) $(addprefix dotnetlibs/, System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) - $(CSC) -out:$@ -noconfig -nostdlib -target:library $(addprefix -r:$(TESTRUN_FOLDER)/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, System.Management.Automation.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) ${COREREF} $(TEST_SRCS) + $(CSC) -out:$@ -noconfig -nostdlib -target:library $(addprefix -r:$(TESTRUN_FOLDER)/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, System.Management.Automation.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) $(COREREF) $(TEST_SRCS) From 962e3671b171f21e9e9d30c709203219b15bfeb4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 3 Sep 2015 16:04:12 -0700 Subject: [PATCH 11/16] Update xUnit tests for AMSI and repin monad Includes lots of fixes to monad. --- src/monad | 2 +- src/ps_test/test_SecuritySupport.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/monad b/src/monad index d541b0734..38fe674dc 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit d541b073435e55fd96771697e5549cc9a188fa54 +Subproject commit 38fe674dc9c66c2752a322f1986ab6d387016d27 diff --git a/src/ps_test/test_SecuritySupport.cs b/src/ps_test/test_SecuritySupport.cs index 4c3b4b9b1..962dc6670 100644 --- a/src/ps_test/test_SecuritySupport.cs +++ b/src/ps_test/test_SecuritySupport.cs @@ -15,7 +15,9 @@ namespace PSTests [Fact] public static void TestCurrentDomain_ProcessExit() { - AmsiUtils.CurrentDomain_ProcessExit(null, EventArgs.Empty); + Assert.Throws(delegate { + AmsiUtils.CurrentDomain_ProcessExit(null, EventArgs.Empty); + }); } [Fact] From f6e255310b3765ce4f15b13837bd59678bc58e2a Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:40:30 -0700 Subject: [PATCH 12/16] merged upstream changes inside monad --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 01ff8a3f7..d0697c432 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 +Subproject commit d0697c432c1d678e59af3ebd6320e5bc3a432b2f From d4f08a971d1822c64f266c3ddccbcdb1e66044df Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:41:14 -0700 Subject: [PATCH 13/16] changed according to code review --- src/ps_test/test_CorePsPlatform.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index a8bf60eb9..f2fcef456 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -93,35 +93,26 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkWithFileSystemInfo() + public static void TestExistantFileIsHardLink() { - // a file that should exist on every *nix distro - string path = @"/tmp/MyTest"; if (!File.Exists(path)) { File.Create(path); } - // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); MemoryStream stream = new MemoryStream(byteArray); - using (StreamWriter sw = new StreamWriter(stream)) - { - sw.Write("Hello"); - } - // Convert `path` string to FileSystemInfo data type. And now, it should return true FileSystemInfo fd = new FileInfo(path); Assert.True(Platform.NonWindowsIsHardLink(fd)); } [Fact] - public static void TestIsHardLinkFailsWithDirectoryWithFileSystemInfo() + public static void TestDirectoryIsHardLink() { - // A folder that should exist on every *nix system string path = @"/tmp"; // Convert `path` string to FileSystemInfo data type. And now, it should return true @@ -130,7 +121,7 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkFailsWithNonexistantFileWithFileSystemInfo() + public static void TestNonExistantIsHardLink() { // A file that should *never* exist on a test machine: string path = @"/tmp/ThisFileShouldNotExistOnTestMachines"; From bd6e4ef88511b80ae1860460bed2a3234aef7ea5 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:42:28 -0700 Subject: [PATCH 14/16] fixed typo --- src/ps_test/test_CorePsPlatform.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index f2fcef456..e11826091 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -101,7 +101,8 @@ namespace PSTests File.Create(path); } // Create a file to write to using StreamWriter. - // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + // convert string to stream. On Windows, this appears to be handled, but on *nix, + // we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); MemoryStream stream = new MemoryStream(byteArray); From 4dc037cc4e3a815cd7ea2679b2a848c3ad7d4e9a Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 4 Sep 2015 15:19:21 -0700 Subject: [PATCH 15/16] Repin monad to latest fixes Resolves all approved work items prior to resubmission of a code review to the PowerShell team. --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 38fe674dc..9aecfb12f 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 38fe674dc9c66c2752a322f1986ab6d387016d27 +Subproject commit 9aecfb12f69d91908812751e1b69d7c5c8098e07 From cec380e4b4e4f13e61d1b4d0e490254eb73171bf Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 8 Sep 2015 11:47:13 -0700 Subject: [PATCH 16/16] added additional testing according to code review --- src/pester-tests/Test-Test-Path.Tests.ps1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pester-tests/Test-Test-Path.Tests.ps1 b/src/pester-tests/Test-Test-Path.Tests.ps1 index 144442fa1..83c18d1f4 100644 --- a/src/pester-tests/Test-Test-Path.Tests.ps1 +++ b/src/pester-tests/Test-Test-Path.Tests.ps1 @@ -10,10 +10,13 @@ It "Should allow piping objects to it" { { $testdirectory | Test-Path } | Should Not Throw + + $testdirectory | Test-Path | Should Be $true + "/usr/bin/totallyFakeDirectory" | Test-Path | Should Be $false } It "Should return a boolean data type" { - { Test-Path -Path $testdirectory } | Should Be ($true -or $false) + { Test-Path -Path $testdirectory } | Should Be $true } It "Should be called on a nonexistant path without error" { @@ -29,13 +32,16 @@ } It "Should be able to accept a regular expression" { - { Test-Path -Path "/u*" } | Should Not Throw + { Test-Path -Path "/u*" } | Should Not Throw + { Test-Path -Path "/u[a-z]r" } | Should Not Throw } It "Should be able to return the correct result when a regular expression is used" { - Test-Path -Path "/u*" | Should Be $true + Test-Path -Path "/u*" | Should Be $true + Test-Path -Path "/u[a-z]*" | Should Be $true - Test-Path -Path "/aoeu*" | Should Be $false + Test-Path -Path "/aoeu*" | Should Be $false + Test-Path -Path "/u[A-Z]" | Should Be $false } It "Should return false when the Leaf pathtype is used on a directory" { @@ -93,10 +99,12 @@ It "Should return false if regular expressions are used with the LiteralPath switch" { Test-Path -LiteralPath /*sr/bin | Should Be $false + Test-Path -LiteralPath /[usth]sr/bin | Should Be $false } It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" { Test-Path -PSPath /*sr/bin | Should Be $false + Test-Path -PSPath /[aoeu]sr/bin | Should Be $false } It "Should return true if used on components other than filesystem objects" {