Skip to content

Make it easier to install the dotnet CLI tools #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
73069c3
Add bootstrapping code to install dotnet
JamesWTruher Feb 5, 2019
b10fa9c
fix logic for downloading proper dotnet installer.
JamesWTruher Feb 6, 2019
a3379fc
add a version checker for installed dotnet
JamesWTruher Feb 8, 2019
d2b4eca
Add bootstrapping code to install dotnet
JamesWTruher Feb 5, 2019
1e484c6
Fix merge conflicts
JamesWTruher Feb 11, 2019
ef6f4f5
Fix merge conflicts
JamesWTruher Feb 11, 2019
31c39b4
Merge branch 'bootstrap' of https://github.com/JamesWTruher/PSScriptA…
JamesWTruher Feb 11, 2019
7f3ddb3
Handle missing dotnet, and install it.
JamesWTruher Feb 12, 2019
ecc4b3f
Add logic for checking the appropriate version of the Cli tools befor…
JamesWTruher Feb 12, 2019
2df5451
Update appveyor.psm1 to use build script bootstrapping for installing…
JamesWTruher Feb 12, 2019
4d2bf72
make the hunt for the dotnet executable more generic and try harder t…
JamesWTruher Feb 13, 2019
d9833c4
Fix typo when checking for usable versions of dotnet
JamesWTruher Feb 13, 2019
4909995
use -version rather than ambiguous -v when installing dotnet
JamesWTruher Feb 13, 2019
b3d23cf
Improve error message when hunting for cli version
JamesWTruher Feb 13, 2019
020c086
ignore errors when first attempting to find dotnet executable
JamesWTruher Feb 14, 2019
34835b8
Improve logic for handling a system where dotnet has never been insta…
JamesWTruher Feb 14, 2019
e3752cc
fine tune messages emitted during the hunt for dotnet
JamesWTruher Feb 14, 2019
8a7ea47
additional logic for finding dotnet executable
JamesWTruher Feb 14, 2019
c19ae0a
harden search for dotnet
JamesWTruher Feb 14, 2019
a3e81e1
Attempt to quieten build output.
JamesWTruher Feb 14, 2019
16ae243
Fix tostring method for portable version
JamesWTruher Feb 15, 2019
1747530
add -Raw flag to Get-GlobalJsonSdkVersion
JamesWTruher Feb 15, 2019
264652d
Attempt to harden the upload code
JamesWTruher Feb 15, 2019
cd1cbb9
upgrade pester version to 4.4.4
JamesWTruher Feb 15, 2019
fb8013a
Force the testsuite TestFixture to be named 'Pester' to get through a…
JamesWTruher Feb 16, 2019
44a370b
Emit env:LANG to output before executing tests
JamesWTruher Feb 16, 2019
58e9216
Create tests for build module
JamesWTruher Feb 19, 2019
8dcfa81
Add additional tests
JamesWTruher Feb 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions BuildModule.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# these are tests for the build module

import-module -force "./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-DotnetInstallation" {
BeforeAll {
$availableVersions = ConvertTo-PortableVersion -strVersion "2.2.400","2.2.401","2.2.405"
$foundVersion = ConvertTo-PortableVersion -strVersion 2.2.402
$missingVersion = ConvertTo-PortableVersion -strVersion 2.2.410
}

It "Test-DotnetInstallation finds a good version" {
Mock Get-InstalledCLIVersion { return $availableVersions }
Mock Get-GlobalJSonSdkVersion { return $foundVersion }
$result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion)
Assert-MockCalled "Get-InstalledCLIVersion" -Times 1
Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1
$result | Should -Be $true
}

It "Test-DotnetInstallation cannot find a good version should return false" {
Mock Get-InstalledCLIVersion { return $availableVersions }
Mock Get-GlobalJSonSdkVersion { return $missingVersion }
$result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion)
Assert-MockCalled "Get-InstalledCLIVersion" -Times 1
Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1
$result | Should -Be $false
}
}

Context "Receive-DotnetInstallScript" {

Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.sh }
It "Downloads the proper non-Windows file" {
try {
push-location TestDrive:
Receive-DotnetInstallScript -platform NonWindows
"TestDrive:/dotnet-install.sh" | Should -Exist
}
finally {
Pop-Location
}
}

Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.ps1 }
It "Downloads the proper file Windows file" {
try {
push-location TestDrive:
Receive-DotnetInstallScript -platform "Windows"
"TestDrive:/dotnet-install.ps1" | Should -Exist
}
finally {
Pop-Location
}
}

}

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 &lt;ScriptBlock&gt;, /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 | ?{ $_.result -eq "Success" }).Count |Should -Be 1
}
It "Get-TestResults finds 1 failure" {
@($results | ?{ $_.result -eq "Failure" }).Count |Should -Be 1
}
It "Get-TestFailures finds 1 failure" {
$failures.Count | Should -Be 1
}
}
}
9 changes: 8 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ param(
[switch] $Test,

[Parameter(ParameterSetName='Test')]
[switch] $InProcess
[switch] $InProcess,

[Parameter(ParameterSetName='Bootstrap')]
[switch] $Bootstrap
)

END {
Expand All @@ -58,6 +61,10 @@ END {
}
Start-ScriptAnalyzerBuild @buildArgs
}
"Bootstrap" {
Install-DotNet
return
}
"Test" {
Test-ScriptAnalyzer -InProcess:$InProcess
return
Expand Down
Loading