-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathBuildModule.tests.ps1
More file actions
99 lines (94 loc) · 5.55 KB
/
BuildModule.tests.ps1
File metadata and controls
99 lines (94 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# these are tests for the build module
import-module -force "$PSScriptRoot\..\..\build.psm1"
Describe "Build Module Tests" {
Context "Global.json" {
BeforeAll {
$globalJson = Get-Content (Join-Path "$PSScriptRoot\..\..\" global.json) | ConvertFrom-Json
$expectedVersion = $globalJson.sdk.version
$result = Get-GlobalJsonSdkVersion
}
$propertyTestcases = @{ Name = "Major"; Type = "System.Int32" },
@{ Name = "Minor"; Type = "System.Int32" },
@{ Name = "Patch"; Type = "System.Int32" },
@{ Name = "PrereleaseLabel"; Type = "System.String" }
It "Get-GlobalJsonSdkVersion returns a portable version object with property '<Name>' with type '<Type>'" -TestCases $propertyTestcases {
param ( $Name, $Type )
$result.psobject.properties[$Name] | Should -BeOfType [System.Management.Automation.PSNoteProperty]
$result.psobject.properties[$Name].TypeNameOfValue | Should -Be $Type
}
It "Can retrieve the version from global.json" {
$result = Get-GlobalJsonSdkVersion
$resultString = "{0}.{1}.{2}" -f $result.Major,$result.Minor,$result.Patch
if ( $result.prereleasestring ) { $resultString += "-" + $result.prereleasestring }
$resultString | Should -Be $expectedVersion
}
}
Context "Test-SuiteableDotnet" {
It "Test-SuitableDotnet should return true when the expected version matches the installed version" {
Test-SuitableDotnet -availableVersions 2.1.2 -requiredVersion 2.1.2 | Should -Be $true
}
It "Test-SuitableDotnet should return true when the expected version matches the available versions" {
Test-SuitableDotnet -availableVersions "2.1.1","2.1.2","2.1.3" -requiredVersion 2.1.2 | Should -Be $true
}
It "Test-SuitableDotnet should return false when the expected version does not match an available" {
Test-SuitableDotnet -availableVersions "2.2.100","2.2.300" -requiredVersion 2.2.200 | Should -Be $false
}
It "Test-SuitableDotnet should return false when the expected version does not match an available" {
Test-SuitableDotnet -availableVersions "2.2.100","2.2.300" -requiredVersion 2.2.105 | Should -Be $false
}
It "Test-SuitableDotnet should return true when the expected version matches an available" {
Test-SuitableDotnet -availableVersions "2.2.150","2.2.300" -requiredVersion 2.2.105 | Should -Be $true
}
It "Test-SuitableDotnet should return false when the expected version does not match an available" {
Test-SuitableDotnet -availableVersions "2.2.400","2.2.401","2.2.405" -requiredVersion "2.2.410" | Should -Be $false
}
}
Context "Test result functions" {
BeforeAll {
$xmlFile = @'
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<test-results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="nunit_schema_2.5.xsd" name="Pester" total="2" errors="0" failures="1" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2019-02-19" time="11:36:56">
<environment platform="Darwin" clr-version="Unknown" os-version="18.2.0" cwd="/Users/jimtru/src/github/forks/JamesWTruher/PSScriptAnalyzer" user="jimtru" user-domain="" machine-name="Jims-Mac-mini.guest.corp.microsoft.com" nunit-version="2.5.8.0" />
<culture-info current-culture="en-US" current-uiculture="en-US" />
<test-suite type="TestFixture" name="Pester" executed="True" result="Failure" success="False" time="0.0982" asserts="0" description="Pester">
<results>
<test-suite type="TestFixture" name="/tmp/bad.tests.ps1" executed="True" result="Failure" success="False" time="0.0982" asserts="0" description="/tmp/bad.tests.ps1">
<results>
<test-suite type="TestFixture" name="test function" executed="True" result="Failure" success="False" time="0.084" asserts="0" description="test function">
<results>
<test-case description="a passing test" name="test function.a passing test" time="0.0072" asserts="0" success="True" result="Success" executed="True" />
<test-case description="a failing test" name="test function.a failing test" time="0.0268" asserts="0" success="False" result="Failure" executed="True">
<failure>
<message>Expected 2, but got 1.</message>
<stack-trace>at <ScriptBlock>, /tmp/bad.tests.ps1: line 3
3: It "a failing test" { 1 | Should -Be 2 }</stack-trace>
</failure>
</test-case>
</results>
</test-suite>
</results>
</test-suite>
</results>
</test-suite>
</test-results>
'@
$xmlFile | out-file TESTDRIVE:/results.xml
$results = @(Get-TestResults -logfile TESTDRIVE:/results.xml)
$failures = @(Get-TestFailures -logfile TESTDRIVE:/results.xml)
}
It "Get-TestResults finds 2 results" {
$results.Count | Should -Be 2
}
It "Get-TestResults finds 1 pass" {
@($results | Where-Object -FilterScript { $_.result -eq "Success" }).Count | Should -Be 1
}
It "Get-TestResults finds 1 failure" {
@($results | Where-Object -FilterScript { $_.result -eq "Failure" }).Count | Should -Be 1
}
It "Get-TestFailures finds 1 failure" {
$failures.Count | Should -Be 1
}
}
}