Merged in upstream changes into branch

Merge branch 'develop' of mshttps://msostc.visualstudio.com/DefaultCollection/PS/_git/monad-linux into dev/184-New-Item-pester
This commit is contained in:
Zachary Folwick
2015-09-04 10:58:13 -07:00
14 changed files with 538 additions and 52 deletions
+40 -29
View File
@@ -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 ${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.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}
$(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
@@ -181,20 +181,31 @@ run-interactive: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-relea
run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
exec_env/app_base/runps.sh --file $(PSSCRIPT)
pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
# execute the pester tests, pester needs a TEMP environment variable to be set
exec_env/app_base/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester'
test: $(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) pester-tests dotnetlibs/monad_native
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
# run the c++ tests
cd dotnetlibs && ./monad_native
# test the 3rdparty/hashbang sample
PATH=$(PATH):$(shell pwd)/exec_env/app_base $(shell pwd)/3rdparty/hashbang/script.ps1
# easy way to run individual PowerShell scripts, `make script.ps1` where the path is relative to monad-linux/scripts (with TEMP set for Pester)
%.ps1: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
TEMP=/tmp exec_env/app_base/runps.sh --file ../../$@
run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-debug-clr
PAL_DBG_CHANNELS="+LOADER.TRACE" exec_env/app_base/runps-simple.sh get-location
native-tests: dotnetlibs/monad_native
# execute the native C++ tests
cd 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
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
exec_env/app_base/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester'
hashbang-tests:
# execute the 3rdparty/hashbang example
PATH=$(PATH):$(shell pwd)/exec_env/app_base $(shell pwd)/3rdparty/hashbang/script.ps1
test: native-tests xunit-tests pester-tests hashbang-tests
trace: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
exec_env/app_base/runps-simple-trace.sh get-location
+2 -2
View File
File diff suppressed because one or more lines are too long
+72
View File
@@ -595,6 +595,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to convert the value of CimProperty {0} to the property value of class {1}..
/// </summary>
internal static string ConvertCimPropertyToObjectPropertyFailed {
get {
return ResourceManager.GetString("ConvertCimPropertyToObjectPropertyFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not get dispatch ID for {0} (error: {1})..
/// </summary>
@@ -838,6 +847,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Keyword &apos;{0}&apos; already defined in the configuration..
/// </summary>
internal static string DuplicateKeywordDefinition {
get {
return ResourceManager.GetString("DuplicateKeywordDefinition", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Duplicate named arguments &apos;{0}&apos; are not allowed..
/// </summary>
@@ -1090,6 +1108,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Property {0} of PowerShell class {1} is not declared as array type, but defined in its configuration instance as instance array type..
/// </summary>
internal static string ExpectArrayTypeOfPropertyInPSClass {
get {
return ResourceManager.GetString("ExpectArrayTypeOfPropertyInPSClass", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An expression was expected after &apos;(&apos;..
/// </summary>
@@ -1430,6 +1457,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to create an object of PowerShell class {0}..
/// </summary>
internal static string InstantiatePSClassObjectFailed {
get {
return ResourceManager.GetString("InstantiatePSClassObjectFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos;: Interface name expected..
/// </summary>
@@ -1538,6 +1574,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The hashtable supplied to the Desired State Configuration resource {0} is not valid. The key or value cannot be null or empty..
/// </summary>
internal static string InvalidHashtable {
get {
return ResourceManager.GetString("InvalidHashtable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The member &apos;{0}&apos; is not valid. Valid members are
///&apos;{1}&apos;..
@@ -1602,6 +1647,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The username supplied to the Desired State Configuration resource {0} is not valid. The username cannot be null or empty..
/// </summary>
internal static string InvalidPassword {
get {
return ResourceManager.GetString("InvalidPassword", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The PowerShell data file &apos;{0}&apos; is invalid since it cannot be evaluated into a Hashtable object..
/// </summary>
@@ -1665,6 +1719,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The username supplied to the Desired State Configuration resource {0} is not valid. The username cannot be null or empty..
/// </summary>
internal static string InvalidUserName {
get {
return ResourceManager.GetString("InvalidUserName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Expression is not allowed in a Using expression..
/// </summary>
@@ -2925,6 +2988,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Property {0} is not declared in PowerShell class {1}, but defined in its configuration instance..
/// </summary>
internal static string PropertyNotDeclaredInPSClass {
get {
return ResourceManager.GetString("PropertyNotDeclaredInPSClass", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The property &apos;{0}&apos; cannot be found on this object. Verify that the property exists and can be set..
/// </summary>
Binary file not shown.
@@ -250,6 +250,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to find vmcompute.dll. The Hyper-V role may not be enabled on this machine..
/// </summary>
internal static string CannotFindVmComputeDll {
get {
return ResourceManager.GetString("CannotFindVmComputeDll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The call to Windows API GetStdHandle to get the Standard Error handle resulted in an error code: {0}..
/// </summary>
@@ -538,6 +547,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Could not find the toolkit, &apos;{0}&apos;. The toolkit must be a file named &apos;{1}&apos; within a &apos;Toolkits&apos; directory in a module in the current module path..
/// </summary>
internal static string CouldNotFindToolkit {
get {
return ResourceManager.GetString("CouldNotFindToolkit", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is not a valid value for the parameter {1}. The value must be greater than or equal to 0..
/// </summary>
@@ -767,6 +785,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Could not parse visible command defintion for &apos;{0}&apos;. The visible command definition must be a hashtable with the keys of &apos;Name&apos; and &apos;Parameters&apos;. The value of the &apos;Parameters&apos; key must be a collection of hashtables with the keys &apos;Name&apos;, and optionally either &apos;ValidateSet&apos; or &apos;ValidatePattern&apos;..
/// </summary>
internal static string DISCCommandModificationSyntax {
get {
return ResourceManager.GetString("DISCCommandModificationSyntax", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Company associated with this session configuration.
/// </summary>
@@ -956,6 +983,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to User roles (security groups), and the additional configuration settings that should be applied to them.
/// </summary>
internal static string DISCRoleDefinitionsComment {
get {
return ResourceManager.GetString("DISCRoleDefinitionsComment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version number of the schema used for this configuration file.
/// </summary>
@@ -974,6 +1010,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Toolkits to apply to this session configuration. This toolkit must be defined as a session configuration file named after that toolkit within a &apos;Toolkits&apos; directory in a module in the current module path..
/// </summary>
internal static string DISCToolkitsToLoadComment {
get {
return ResourceManager.GetString("DISCToolkitsToLoadComment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Specifies the transport options for this session configuration.
/// </summary>
@@ -1629,6 +1674,33 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The &apos;Roles&apos; entry must be a hashtable, but was a {0}..
/// </summary>
internal static string InvalidRoleEntry {
get {
return ResourceManager.GetString("InvalidRoleEntry", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The key &apos;{0}&apos; is not valid in a toolkit or role definition..
/// </summary>
internal static string InvalidRoleToolkitKey {
get {
return ResourceManager.GetString("InvalidRoleToolkitKey", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not convert the value of the &apos;{0}&apos; role entry to a hashtable. The &apos;Roles&apos; entry must be a hashtable with group names for keys, where the value associated with each key is another hashtable of session configuration properties for that role..
/// </summary>
internal static string InvalidRoleValue {
get {
return ResourceManager.GetString("InvalidRoleValue", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is not a valid schema value. Valid values are &quot;http&quot; and &quot;https&quot;..
/// </summary>
@@ -3053,6 +3125,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Failed to create an instance of RemoteSessionHyperVSocketServer..
/// </summary>
internal static string RemoteSessionHyperVSocketServerConstructorFailure {
get {
return ResourceManager.GetString("RemoteSessionHyperVSocketServerConstructorFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Remote transport error: {0}.
/// </summary>
@@ -3837,6 +3918,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to WSMan Initialization failed with error code: {0}..
/// </summary>
internal static string WSManInitFailed {
get {
return ResourceManager.GetString("WSManInitFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The maximum number of WS-Man URI redirections to allow while connecting to a remote computer.
/// </summary>
+7
View File
@@ -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 "$@"
+1 -1
View File
@@ -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)
+139
View File
@@ -0,0 +1,139 @@
Describe "Test-Remove-Item" {
$testpath = "/tmp/"
$testfile = "testfile.txt"
$testfilepath = $testpath + $testfile
Context "File removal Tests" {
BeforeEach {
New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force
Test-Path $testfilepath | Should Be $true
}
It "Should be able to be called on a regular file without error using the Path switch" {
{ Remove-Item -Path $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should be able to be called on a file without the Path switch" {
{ Remove-Item $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the rm alias" {
{ rm $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the del alias" {
{ del $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the erase alias" {
{ erase $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should be able to call the ri alias" {
{ ri $testfilepath } | Should Not Throw
Test-Path $testfilepath | Should Be $false
}
It "Should not be able to remove a read-only document without using the force switch" {
# Set to read only
Set-ItemProperty -Path $testfilepath -Name IsReadOnly -Value $true
# attempt to remove the file
{ Remove-Item $testfilepath -ErrorAction SilentlyContinue } | Should Not Throw
# validate
Test-Path $testfilepath | Should Be $true
# remove using the -force switch on the readonly object
Remove-Item $testfilepath -Force
# Validate
Test-Path $testfilepath | Should Be $false
}
It "Should be able to remove all files matching a regular expression with the include switch" {
# Create multiple files with specific string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file3.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string - already done in BeforeEach
# Delete the specific string
Remove-Item /tmp/* -Include file*.txt
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-path /tmp/file1.txt | Should Be $false
Test-path /tmp/file2.txt | Should Be $false
Test-path /tmp/file3.txt | Should Be $false
Test-Path $testfilepath | Should Be $true
# Delete the non-matching strings
Remove-Item $testfilepath
Test-Path $testfilepath | Should Be $false
}
It "Should be able to not remove any files matching a regular expression with the exclude switch" {
# Create multiple files with specific string
New-Item -Name file1.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
New-Item -Name file2.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Create a single file that does not match that string
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
# Delete the specific string
Remove-Item /tmp/file* -Exclude *.wav -Include *.txt
# validate that the string under test was deleted, and the nonmatching strings still exist
Test-Path /tmp/file1.wav | Should Be $true
Test-Path /tmp/file2.wav | Should Be $true
Test-Path /tmp/file1.txt | Should Be $false
# Delete the non-matching strings
Remove-Item /tmp/file1.wav
Remove-Item /tmp/file2.wav
Test-Path /tmp/file1.wav | Should Be $false
Test-Path /tmp/file2.wav | Should Be $false
}
}
Context "Directory Removal Tests" {
$testdirectory = "/tmp/testdir"
$testsubdirectory = $testdirectory + "/subd"
BeforeEach {
New-Item -Name "testdir" -Path "/tmp/" -ItemType "directory" -Force
Test-Path $testdirectory | Should Be $true
}
It "Should be able to remove a directory" {
{ Remove-Item $testdirectory } | Should Not Throw
Test-Path $testdirectory | Should Be $false
}
It "Should be able to recursively delete subfolders" {
New-Item -Name "subd" -Path $testdirectory -ItemType "directory"
New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum"
$complexDirectory = $testsubdirectory + "/" + $testfile
test-path $complexDirectory | Should Be $true
{ Remove-Item $testdirectory -Recurse} | Should Not Throw
Test-Path $testdirectory | Should Be $false
}
}
}
+68 -18
View File
@@ -1,36 +1,86 @@
Describe "Test-Split-Path" {
<#
Dependencies:
1. Split-Path - FUT
2. ForEach
3. Object piping
4. ls/Get-ChildItem - filter output of ls
#>
It "Should return a string object when invoked" {
(Split-Path .).GetType().Name | Should Be "String"
(Split-Path . -Leaf).GetType().Name | Should Be "String"
(Split-Path . -Resolve).GetType().Name | Should Be "String"
( Split-Path . ).GetType().Name | Should Be "String"
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
( Split-Path . -Resolve ).GetType().Name | Should Be "String"
}
It "Should return the name of the drive when the qualifier switch is used" {
Split-Path / -Qualifier | Should Be "/"
Split-Path / -Qualifier | Should Be "/"
Split-Path /usr/bin -Qualifier | Should Be "/"
}
It "Should return the parent folder name when the leaf switch is used" {
Split-Path . -Leaf | Should be "pester-tests"
It "Should error when using the qualifier switch for a windows path while on a nonwindows machine" {
# ErrorAction SilentlyContinue merely suppresses the error from the console.
# Throwing exceptions still seen by Pester.
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
It "Should error when no directory separator characters are used with a qualifier" {
Split-Path "abadTest" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
It "Should return the path when the noqualifier switch is used on a Linux system" {
{ Split-Path /usr/bin -NoQualifier } | Should Not Throw
Split-Path /usr/bin -NoQualifier | Should Be "/usr/bin"
}
It "Should return the base name when the leaf switch is used" {
Split-Path /usr/bin -Leaf | Should be "bin"
Split-Path /usr/local/bin -Leaf | Should be "bin"
Split-Path usr/bin -Leaf | Should be "bin"
Split-Path ./bin -Leaf | Should be "bin"
Split-Path bin -Leaf | Should be "bin"
}
It "Should be able to accept regular expression input and output an array for multiple objects" {
(Split-Path *Get*.ps1 -Leaf -Resolve).GetType().BaseType.Name | Should Be "Array"
$testDir = "./tmp"
Remove-Item $testDir -Recurse -Force -ErrorAction Ignore
$testFile1 = "testfile1.ps1"
$testFile2 = "testfile2.ps1"
$testFilePath1 = $testDir + "/" + $testFile1
$testFilePath2 = $testDir + "/" + $testFile2
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
Test-Path $testFilePath1 | Should Be $true
Test-Path $testFilePath2 | Should Be $true
$actual = ( Split-Path $testDir/*file*.ps1 -Leaf -Resolve ) | Sort-Object
$actual.GetType().BaseType.Name | Should Be "Array"
$actual[0] | Should Be $testFile1
$actual[1] | Should Be $testFile2
Remove-Item $testDir -Recurse -Force -ErrorAction Ignore
Test-Path $testDir | Should Be $false
}
It "Should be able to tell if a given path is an absolute path" {
(Split-Path /usr/bin -IsAbsolute) | Should be $true
(Split-Path . -IsAbsolute) | Should be $false
( Split-Path /usr/bin -IsAbsolute ) | Should be $true
( Split-Path .. -IsAbsolute ) | Should be $false
( Split-Path /usr/.. -IsAbsolute ) | Should be $true
( Split-Path /usr/../ -IsAbsolute ) | Should be $true
( Split-Path ../ -IsAbsolute ) | Should be $false
( Split-Path . -IsAbsolute ) | Should be $false
( Split-Path ~/ -IsAbsolute ) | Should be $false
( Split-Path ~/.. -IsAbsolute ) | Should be $false
( Split-Path ~/../.. -IsAbsolute ) | Should be $false
}
It "Should support piping" {
("." | Split-Path -leaf) | Should Be "pester-tests"
( "/usr/bin" | Split-Path ) | Should Be "/usr"
}
It "Should return the path up to the parent of the directory when Parent switch is used" {
Split-Path "/usr/bin" -Parent | Should Be "/usr"
Split-Path "/usr/local/bin" -Parent | Should Be "/usr/local"
Split-Path "usr/local/bin" -Parent | Should Be "usr/local"
}
It "Should throw if a parameterSetName is incorrect" {
{ Split-Path "/usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
}
}
+69
View File
@@ -1,5 +1,6 @@
using Xunit;
using System;
using System.IO;
using System.Diagnostics;
using System.Management.Automation;
@@ -65,5 +66,73 @@ namespace PSTests
Assert.Equal(username, Platform.NonWindowsGetUserName());
}
}
[Fact]
public static void TestGetMachineName()
{
var startInfo = new ProcessStartInfo
{
FileName = @"/usr/bin/env",
Arguments = "hostname",
RedirectStandardOutput = true,
UseShellExecute = false
};
using (Process process = Process.Start(startInfo))
{
// Get output of call to hostname without trailing newline
string hostname = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit();
// The process should return an exit code of 0 on success
Assert.Equal(0, process.ExitCode);
// It should be the same as what our platform code returns
Assert.Equal(hostname, Platform.NonWindowsGetMachineName());
}
}
[Fact]
public static void TestExistantFileIsHardLink()
{
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);
// 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 TestDirectoryIsHardLink()
{
string path = @"/tmp";
// 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 TestNonExistantIsHardLink()
{
// 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));
}
}
}
+48
View File
@@ -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();
}
}
}
}
}