2020-07-02 02:36:09 +08:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
#
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
End-to-End tests for the vcpkg executable.
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
These tests cover the command line interface and broad functions of vcpkg, including `install`, `remove` and certain
|
|
|
|
binary caching scenarios. They use the vcpkg executable in the current directory.
|
|
|
|
|
|
|
|
.PARAMETER Triplet
|
|
|
|
The triplet to use for testing purposes.
|
|
|
|
|
|
|
|
.PARAMETER WorkingRoot
|
|
|
|
The location used as scratch space for testing.
|
|
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string]$Triplet,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string]$WorkingRoot
|
|
|
|
)
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
$TestingRoot = Join-Path $WorkingRoot 'testing'
|
|
|
|
$buildtreesRoot = Join-Path $TestingRoot 'buildtrees'
|
|
|
|
$installRoot = Join-Path $TestingRoot 'installed'
|
|
|
|
$packagesRoot = Join-Path $TestingRoot 'packages'
|
|
|
|
$NuGetRoot = Join-Path $TestingRoot 'nuget'
|
|
|
|
$NuGetRoot2 = Join-Path $TestingRoot 'nuget2'
|
|
|
|
$ArchiveRoot = Join-Path $TestingRoot 'archives'
|
|
|
|
$commonArgs = @(
|
|
|
|
"--triplet",
|
|
|
|
$Triplet,
|
|
|
|
"--x-buildtrees-root=$buildtreesRoot",
|
|
|
|
"--x-install-root=$installRoot",
|
|
|
|
"--x-packages-root=$packagesRoot"
|
|
|
|
)
|
|
|
|
|
2020-07-09 06:08:17 +08:00
|
|
|
function Refresh-TestRoot {
|
|
|
|
Remove-Item -Recurse -Force $TestingRoot -ErrorAction SilentlyContinue
|
|
|
|
mkdir $TestingRoot
|
|
|
|
mkdir $NuGetRoot
|
|
|
|
}
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
function Require-FileExists {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[string]$File
|
|
|
|
)
|
|
|
|
if (-Not (Test-Path $File)) {
|
|
|
|
throw "'$CurrentTest' failed to create file '$File'"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function Require-FileNotExists {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[string]$File
|
|
|
|
)
|
|
|
|
if (Test-Path $File) {
|
|
|
|
throw "'$CurrentTest' should not have created file '$File'"
|
|
|
|
}
|
|
|
|
}
|
2020-07-09 06:08:17 +08:00
|
|
|
function Throw-IfFailed {
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
throw "'$CurrentTest' had a step with a nonzero exit code"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-not $IsLinux -and -not $IsMacOS)
|
|
|
|
{
|
|
|
|
Refresh-TestRoot
|
|
|
|
# Test msbuild props and targets
|
|
|
|
$CurrentTest = "zlib:x86-windows-static msbuild scripts\testing\integrate-install\..."
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg $commonArgs install zlib:x86-windows-static --x-binarysource=clear
|
|
|
|
Throw-IfFailed
|
|
|
|
foreach ($project in @("VcpkgTriplet", "VcpkgTriplet2", "VcpkgUseStatic", "VcpkgUseStatic2")) {
|
|
|
|
$CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj"
|
|
|
|
./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ "
|
|
|
|
Throw-IfFailed
|
|
|
|
Remove-Item -Recurse -Force $TestingRoot\int
|
|
|
|
Remove-Item -Recurse -Force $TestingRoot\out
|
|
|
|
}
|
|
|
|
$CurrentTest = "zlib:x86-windows msbuild scripts\testing\integrate-install\..."
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg $commonArgs install zlib:x86-windows --x-binarysource=clear
|
|
|
|
Throw-IfFailed
|
|
|
|
foreach ($project in @("Project1", "NoProps")) {
|
|
|
|
$CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj"
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ "
|
|
|
|
Throw-IfFailed
|
|
|
|
Remove-Item -Recurse -Force $TestingRoot\int
|
|
|
|
Remove-Item -Recurse -Force $TestingRoot\out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Refresh-TestRoot
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
# Test simple installation
|
2020-07-10 06:14:05 +08:00
|
|
|
$args = $commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;files,$ArchiveRoot,write;nuget,$NuGetRoot,readwrite")
|
2020-07-02 02:36:09 +08:00
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
|
|
|
|
# Test simple removal
|
|
|
|
$args = $commonArgs + @("remove", "rapidjson")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
|
|
|
|
# Test restoring from files archive
|
2020-10-07 05:34:59 +08:00
|
|
|
$args = $commonArgs + @("install","rapidjson","--x-binarysource=clear;files,$ArchiveRoot,read")
|
2020-07-02 02:36:09 +08:00
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Remove-Item -Recurse -Force $installRoot
|
|
|
|
Remove-Item -Recurse -Force $buildtreesRoot
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileNotExists "$buildtreesRoot/rapidjson/src"
|
2020-10-07 05:34:59 +08:00
|
|
|
Require-FileExists "$buildtreesRoot/detect_compiler"
|
|
|
|
|
|
|
|
# Test --no-binarycaching
|
|
|
|
$args = $commonArgs + @("install","rapidjson","--no-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Remove-Item -Recurse -Force $installRoot
|
|
|
|
Remove-Item -Recurse -Force $buildtreesRoot
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
|
|
|
Throw-IfFailed
|
|
|
|
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileExists "$buildtreesRoot/rapidjson/src"
|
|
|
|
Require-FileExists "$buildtreesRoot/detect_compiler"
|
|
|
|
|
|
|
|
# Test --editable
|
|
|
|
$args = $commonArgs + @("install","rapidjson","--editable","--x-binarysource=clear;files,$ArchiveRoot,read")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Remove-Item -Recurse -Force $installRoot
|
|
|
|
Remove-Item -Recurse -Force $buildtreesRoot
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
|
|
|
Throw-IfFailed
|
|
|
|
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileExists "$buildtreesRoot/rapidjson/src"
|
|
|
|
Require-FileNotExists "$buildtreesRoot/detect_compiler"
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
# Test restoring from nuget
|
|
|
|
$args = $commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;nuget,$NuGetRoot")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Remove-Item -Recurse -Force $installRoot
|
|
|
|
Remove-Item -Recurse -Force $buildtreesRoot
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileNotExists "$buildtreesRoot/rapidjson/src"
|
|
|
|
|
|
|
|
# Test four-phase flow
|
|
|
|
$args = $commonArgs + @("install","rapidjson","--dry-run","--x-write-nuget-packages-config=$TestingRoot/packages.config")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Remove-Item -Recurse -Force $installRoot -ErrorAction SilentlyContinue
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileNotExists "$buildtreesRoot/rapidjson/src"
|
|
|
|
Require-FileExists "$TestingRoot/packages.config"
|
|
|
|
|
2020-08-11 01:22:51 +08:00
|
|
|
if ($IsLinux -or $IsMacOS) {
|
|
|
|
mono $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot"
|
|
|
|
Throw-IfFailed
|
|
|
|
} else {
|
|
|
|
& $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot"
|
|
|
|
Throw-IfFailed
|
|
|
|
}
|
2020-07-02 02:36:09 +08:00
|
|
|
|
|
|
|
Remove-Item -Recurse -Force $NuGetRoot -ErrorAction SilentlyContinue
|
|
|
|
mkdir $NuGetRoot
|
|
|
|
|
2020-07-10 06:14:05 +08:00
|
|
|
$args = $commonArgs + @("install","rapidjson","tinyxml","--binarycaching","--x-binarysource=clear;nuget,$NuGetRoot2;nuget,$NuGetRoot,write")
|
2020-07-02 02:36:09 +08:00
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
./vcpkg @args
|
2020-07-09 06:08:17 +08:00
|
|
|
Throw-IfFailed
|
2020-07-02 02:36:09 +08:00
|
|
|
Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
|
|
|
|
Require-FileExists "$installRoot/$Triplet/include/tinyxml.h"
|
|
|
|
Require-FileNotExists "$buildtreesRoot/rapidjson/src"
|
|
|
|
Require-FileExists "$buildtreesRoot/tinyxml/src"
|
|
|
|
|
|
|
|
if ((Get-ChildItem $NuGetRoot -Filter '*.nupkg' | Measure-Object).Count -ne 1) {
|
|
|
|
throw "In '$CurrentTest': did not create exactly 1 NuGet package"
|
|
|
|
}
|
2020-08-11 01:22:51 +08:00
|
|
|
|
|
|
|
# Test export
|
|
|
|
$args = $commonArgs + @("export","rapidjson","tinyxml","--nuget","--nuget-id=vcpkg-export","--nuget-version=1.0.0","--output=vcpkg-export-output","--raw","--zip","--output-dir=$TestingRoot")
|
|
|
|
$CurrentTest = "./vcpkg $($args -join ' ')"
|
|
|
|
Write-Host $CurrentTest
|
|
|
|
Require-FileNotExists "$TestingRoot/vcpkg-export-output"
|
|
|
|
Require-FileNotExists "$TestingRoot/vcpkg-export.1.0.0.nupkg"
|
|
|
|
Require-FileNotExists "$TestingRoot/vcpkg-export-output.zip"
|
|
|
|
./vcpkg @args
|
|
|
|
Require-FileExists "$TestingRoot/vcpkg-export-output"
|
|
|
|
Require-FileExists "$TestingRoot/vcpkg-export.1.0.0.nupkg"
|
|
|
|
Require-FileExists "$TestingRoot/vcpkg-export-output.zip"
|