Merge pull request 195 from dev/import-csv into develop

This commit is contained in:
Andy Schwartzmeyer 2015-10-20 22:12:15 +00:00
commit 042f6067dc
3 changed files with 62 additions and 4 deletions

View file

@ -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

View file

@ -0,0 +1,51 @@
Describe "Test-Import-Csv" {
$testCsv = "./assets/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]
}
}

View file

@ -0,0 +1,5 @@
Column1,Column2,Column 3
data1,1,A
data2,2,B
data3,3,C
data4,4,D
1 Column1 Column2 Column 3
2 data1 1 A
3 data2 2 B
4 data3 3 C
5 data4 4 D