From 5a5169ac60e1400a7058ea22ef498b722890c770 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 12:17:42 -0700 Subject: [PATCH 1/5] Added import-csv test suite --- src/pester-tests/Test-Import-Csv.Tests.ps1 | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/pester-tests/Test-Import-Csv.Tests.ps1 diff --git a/src/pester-tests/Test-Import-Csv.Tests.ps1 b/src/pester-tests/Test-Import-Csv.Tests.ps1 new file mode 100644 index 000000000..649a7fc99 --- /dev/null +++ b/src/pester-tests/Test-Import-Csv.Tests.ps1 @@ -0,0 +1,51 @@ +Describe "Test-Import-Csv" { + $testCsv = "./TestAssets/TestCsv.csv" + + It "Should be able to call without error" { + { Import-Csv $testCsv } | Should Not Throw + } + + It "Should be able to assign to a variable" { + $actual = Import-Csv $testCsv + + $actual | Should Not BeNullOrEmpty + $actual.GetType().BaseType | Should Be array + } + + It "Should have the data from the csv file" { + $actualContent = $(Get-Content $testCsv)[0] + $testContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1 + + $actualContent.IndexOf($testContent) | Should BeGreaterThan -1 + } + + It "Should be able to prepend a custom header" { + $header = "test1","test2","test3" + + $originalContent = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1 + + $testContent = $($(Import-Csv $testCsv -Header $header) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 3 + + # the original csv file doesn't contain the headers + $originalContent.IndexOf($header[0]) | Should Be -1 + + # but it does with the -Header switch! + $testContent[0] | Should Be $header[0] + $testContent[1] | Should Be $header[1] + $testContent[2] | Should Be $header[2] + } + + It "Should be able to use the alias without error" { + { Import-Csv $testCsv } | Should Not Throw + } + + It "Should have the same output between the alias and the full cmdlet name" { + $alias = $($(ipcsv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1 + $cmdlet = $($(Import-Csv $testCsv) | Get-Member) | ? { $_.MemberType -eq "NoteProperty" } | % { $_.Name } | Select-Object -First 1 + + $alias[0] | Should Be $cmdlet[0] + $alias[1] | Should Be $cmdlet[1] + $alias[2] | Should Be $cmdlet[2] + + } +} From 592c05c404471ed3385f76e4e5ad1f44c7269cc3 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 12:18:43 -0700 Subject: [PATCH 2/5] Added a test assets folder to contain csv/html/xml/json/etc files required for reading in --- src/pester-tests/TestAssets/TestCsv.csv | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/pester-tests/TestAssets/TestCsv.csv diff --git a/src/pester-tests/TestAssets/TestCsv.csv b/src/pester-tests/TestAssets/TestCsv.csv new file mode 100644 index 000000000..73a63d899 --- /dev/null +++ b/src/pester-tests/TestAssets/TestCsv.csv @@ -0,0 +1,5 @@ +Column1,Column2,Column 3 +data1,1,A +data2,2,B +data3,3,C +data4,4,D From d383b839645f89cff540884a2e03ccbf435206dd Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 20 Oct 2015 12:19:55 -0700 Subject: [PATCH 3/5] added line to copy TestAssets directory over to working directory used in the build process --- scripts/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/Makefile b/scripts/Makefile index c1d33bf90..77278ac08 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -164,6 +164,7 @@ $(APP_BASE): runps.sh $(RUN_TARGETS) cp -r dotnetlibs/*.so $(APP_BASE) cp dotnetlibs/host_cmdline $(APP_BASE) cp -r $(MONAD)/ext-src/pester $(APP_BASE)/Modules/Pester + cp -r $(ADMIN_GIT_ROOT)/../pester-tests/TestAssets $(APP_BASE) cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE) cp runps*.sh $(APP_BASE) From 67deba1a2a1067a8c1882ffcc503ee932d64a6ea Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 20 Oct 2015 14:55:12 -0700 Subject: [PATCH 4/5] Rename TestAssets to assets --- scripts/Makefile | 1 - src/pester-tests/Test-Import-Csv.Tests.ps1 | 2 +- src/pester-tests/{TestAssets => assets}/TestCsv.csv | 0 3 files changed, 1 insertion(+), 2 deletions(-) rename src/pester-tests/{TestAssets => assets}/TestCsv.csv (100%) diff --git a/scripts/Makefile b/scripts/Makefile index 77278ac08..c1d33bf90 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -164,7 +164,6 @@ $(APP_BASE): runps.sh $(RUN_TARGETS) cp -r dotnetlibs/*.so $(APP_BASE) cp dotnetlibs/host_cmdline $(APP_BASE) cp -r $(MONAD)/ext-src/pester $(APP_BASE)/Modules/Pester - cp -r $(ADMIN_GIT_ROOT)/../pester-tests/TestAssets $(APP_BASE) cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE) cp runps*.sh $(APP_BASE) diff --git a/src/pester-tests/Test-Import-Csv.Tests.ps1 b/src/pester-tests/Test-Import-Csv.Tests.ps1 index 649a7fc99..b880faa04 100644 --- a/src/pester-tests/Test-Import-Csv.Tests.ps1 +++ b/src/pester-tests/Test-Import-Csv.Tests.ps1 @@ -1,5 +1,5 @@ Describe "Test-Import-Csv" { - $testCsv = "./TestAssets/TestCsv.csv" + $testCsv = "./assets/TestCsv.csv" It "Should be able to call without error" { { Import-Csv $testCsv } | Should Not Throw diff --git a/src/pester-tests/TestAssets/TestCsv.csv b/src/pester-tests/assets/TestCsv.csv similarity index 100% rename from src/pester-tests/TestAssets/TestCsv.csv rename to src/pester-tests/assets/TestCsv.csv From 30b2c1fe37308eca9139b34f68702b292548e41f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 20 Oct 2015 15:10:04 -0700 Subject: [PATCH 5/5] Fix pester-tests relative file handling - `APP_BASE` was made into an absolute path - `%.ps1` target now runs without `--file` but instead with `&` - ^ also cd's into pester-tests first --- scripts/Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index c1d33bf90..57e4c6bd2 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -150,7 +150,7 @@ buildtemp: nuget.exe # - copy xUnit libraries # this is the execution environment from which all managed code is run -APP_BASE=exec_env/app_base +APP_BASE=$(MONAD)/scripts/exec_env/app_base .PHONY: $(APP_BASE) $(APP_BASE): runps.sh $(RUN_TARGETS) @@ -187,9 +187,10 @@ run-interactive: shell run-file: $(RUN_TARGETS) prepare $(APP_BASE)/runps.sh --file $(PSSCRIPT) -# easy way to run individual PowerShell scripts, `make script.ps1` where the path is relative to monad-linux/scripts (with TEMP set for Pester) +# easy way to run individual Pester test scripts, `make ../src/pester-tests/Test-Import-Csv.Tests.ps1` +# where the path is relative to monad-linux/scripts (with TEMP set for Pester) %.ps1: $(RUN_TARGETS) prepare - TEMP=/tmp $(APP_BASE)/runps.sh --file $(MONAD)/scripts/$@ + TEMP=/tmp $(APP_BASE)/runps-simple.sh 'cd $(PESTER); & $(MONAD)/scripts/$@' # compiles "Hello World" like executables using .NET Core %.exe: %.cs $(CORECLR) buildtemp @@ -211,8 +212,9 @@ xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) prepare # Pester tests for PowerShell - results in pester-tests.xml # see https://github.com/pester/Pester # requires $TEMP to be set +PESTER=$(MONAD)/src/pester-tests pester-tests: $(RUN_TARGETS) prepare - $(APP_BASE)/runps-simple.sh 'cd $(MONAD)/src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/scripts/pester-tests.xml -OutputFormat NUnitXml' + $(APP_BASE)/runps-simple.sh 'cd $(PESTER); $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/scripts/pester-tests.xml -OutputFormat NUnitXml' # 3rdparty "hashbang" example using runps-file hashbang-tests: all prepare