From 47544c9e77d00a4711125cbf7b978f93d0f41983 Mon Sep 17 00:00:00 2001 From: Simon Hartcher Date: Sat, 11 Apr 2015 01:12:06 +1000 Subject: [PATCH] Add Pester tests for Config and Versions Add Scoop-Config.Tests Add Scoop-Versions.Tests Remove old tests --- test/Scoop-Config.Tests.ps1 | 17 +++++++++++++++++ test/Scoop-Versions.Tests.ps1 | 20 ++++++++++++++++++++ test/ht.ps1 | 11 ----------- test/versions.ps1 | 18 ------------------ 4 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 test/Scoop-Config.Tests.ps1 create mode 100644 test/Scoop-Versions.Tests.ps1 delete mode 100644 test/ht.ps1 delete mode 100644 test/versions.ps1 diff --git a/test/Scoop-Config.Tests.ps1 b/test/Scoop-Config.Tests.ps1 new file mode 100644 index 00000000..f12a6f48 --- /dev/null +++ b/test/Scoop-Config.Tests.ps1 @@ -0,0 +1,17 @@ +. "$psscriptroot\..\lib\core.ps1" +. "$psscriptroot\..\lib\config.ps1" + +describe "hashtable" { + $json = '{ "one": 1, "two": [ { "a": "a" }, "b", 2 ], "three": { "four": 4 } }' + + it "converts pscustomobject to hashtable" { + $obj = convertfrom-json $json + $ht = hashtable $obj + + $ht.one | should beexactly 1 + $ht.two[0].a | should be "a" + $ht.two[1] | should be "b" + $ht.two[2] | should beexactly 2 + $ht.three.four | should beexactly 4 + } +} \ No newline at end of file diff --git a/test/Scoop-Versions.Tests.ps1 b/test/Scoop-Versions.Tests.ps1 new file mode 100644 index 00000000..9eda0f5c --- /dev/null +++ b/test/Scoop-Versions.Tests.ps1 @@ -0,0 +1,20 @@ +. "$psscriptroot\tests.ps1" +. "$psscriptroot\..\lib\versions.ps1" + +describe "versions" { + it 'compares versions with integer-string mismatch' { + $a = '1.8.9' + $b = '1.8.5-1' + $res = compare_versions $a $b + + $res | should be 1 + } + + it 'handles plain string version comparison to int version' { + $a = 'latest' + $b = '20150405' + $res = compare_versions $a $b + + $res | should be 1 + } +} diff --git a/test/ht.ps1 b/test/ht.ps1 deleted file mode 100644 index 753a7173..00000000 --- a/test/ht.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -# testing converting json -> pscustomobject > hashtable - -. "$psscriptroot\..\lib\core.ps1" -. "$psscriptroot\..\lib\config.ps1" - -$json = '{ "one": 1, "two": [ { "a": "a" }, "b", 2 ], "three": { "four": 4 } }' -$global:obj = convertfrom-json $json - -$a = $obj.two[0] - -$global:res = hashtable $obj \ No newline at end of file diff --git a/test/versions.ps1 b/test/versions.ps1 deleted file mode 100644 index cb7fa5b9..00000000 --- a/test/versions.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -. "$psscriptroot\tests.ps1" -. "$psscriptroot\..\lib\versions.ps1" - -test 'compare version with integer-string mismatch' { - $a = '1.8.9' - $b = '1.8.5-1' - $res = compare_versions $a $b - assert $res -eq 1 -} - -test 'handle plain string version comparison to int version' { - $a = 'latest' - $b = '20150405' - $res = compare_versions $a $b - assert $res -eq 1 -} - -test_results \ No newline at end of file