Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
134 changes: 134 additions & 0 deletions scripts/azure-pipelines/end-to-end-tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# 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"
)

Remove-Item -Recurse -Force $TestingRoot -ErrorAction SilentlyContinue
mkdir $TestingRoot
mkdir $NuGetRoot

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'"
}
}

# Test simple installation
$args = $commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;files,$ArchiveRoot,write;nuget,$NuGetRoot,upload")
$CurrentTest = "./vcpkg $($args -join ' ')"
Write-Host $CurrentTest
./vcpkg @args

Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"

# Test simple removal
$args = $commonArgs + @("remove", "rapidjson")
$CurrentTest = "./vcpkg $($args -join ' ')"
Write-Host $CurrentTest
./vcpkg @args

Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"

# Test restoring from files archive
$args = $commonArgs + @("install","rapidjson","--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

Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
Require-FileNotExists "$buildtreesRoot/rapidjson/src"

# 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

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
Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h"
Require-FileNotExists "$buildtreesRoot/rapidjson/src"
Require-FileExists "$TestingRoot/packages.config"

& $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot"

Remove-Item -Recurse -Force $NuGetRoot -ErrorAction SilentlyContinue
mkdir $NuGetRoot

$args = $commonArgs + @("install","rapidjson","tinyxml","--binarycaching","--x-binarysource=clear;nuget,$NuGetRoot2;nuget,$NuGetRoot,upload")
$CurrentTest = "./vcpkg $($args -join ' ')"
Write-Host $CurrentTest
./vcpkg @args
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"
}
1 change: 1 addition & 0 deletions scripts/azure-pipelines/windows/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
cmake.exe -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=ON -B build.x86.debug -S toolsrc
ninja.exe -C build.x86.debug
build.x86.debug\vcpkg-test.exe
powershell.exe -NoProfile -ExecutionPolicy Bypass "scripts\azure-pipelines\end-to-end-tests.ps1 -WorkingRoot \"%cd%\testing\" -triplet x86-windows"
failOnStderr: true
- task: PowerShell@2
displayName: '*** Test Modified Ports and Prepare Test Logs ***'
Expand Down
4 changes: 4 additions & 0 deletions toolsrc/include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,8 @@ namespace vcpkg::Files
bool has_invalid_chars_for_filesystem(const std::string& s);

void print_paths(const std::vector<fs::path>& paths);

/// Performs "lhs / rhs" according to the C++17 Filesystem Library Specification.
/// This function exists as a workaround for TS implementations.
fs::path combine(const fs::path& lhs, const fs::path& rhs);
}
5 changes: 3 additions & 2 deletions toolsrc/include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace vcpkg
virtual void push_failure(const VcpkgPaths& paths, const std::string& abi_tag, const PackageSpec& spec) = 0;
/// Requests the result of `try_restore()` without actually downloading the package. Used by CI to determine
/// missing packages.
virtual RestoreResult precheck(const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action) = 0;
virtual RestoreResult precheck(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
};

IBinaryProvider& null_binary_provider();
Expand All @@ -50,5 +49,7 @@ namespace vcpkg
ExpectedS<std::unique_ptr<IBinaryProvider>> create_binary_provider_from_configs_pure(const std::string& env_string,
View<std::string> args);

std::string generate_nuget_packages_config(const Dependencies::ActionPlan& action);

void help_topic_binary_caching(const VcpkgPaths& paths);
}
11 changes: 8 additions & 3 deletions toolsrc/include/vcpkg/binarycaching.private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ namespace vcpkg

struct XmlSerializer
{
std::string buf;
int indent = 0;

XmlSerializer& emit_declaration();
XmlSerializer& open_tag(StringLiteral sl);
XmlSerializer& start_complex_open_tag(StringLiteral sl);
Expand All @@ -49,6 +46,14 @@ namespace vcpkg
XmlSerializer& text(StringView sv);
XmlSerializer& simple_tag(StringLiteral tag, StringView content);
XmlSerializer& line_break();

std::string buf;

private:
XmlSerializer& emit_pending_indent();

int m_indent = 0;
bool m_pending_indent = false;
};

}
3 changes: 2 additions & 1 deletion toolsrc/include/vcpkg/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ namespace vcpkg::Commands
const CMakeVars::CMakeVarProvider& cmake_vars,
const std::vector<FullPackageSpec>& specs,
const Build::BuildPackageOptions& install_plan_options,
DryRun dry_run);
DryRun dry_run,
const Optional<fs::path>& pkgsconfig_path);
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
}

Expand Down
88 changes: 81 additions & 7 deletions toolsrc/src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <catch2/catch.hpp>
#include <vcpkg/binarycaching.private.h>
#include <vcpkg/binarycaching.h>
#include <vcpkg/base/files.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/vcpkgcmdarguments.h>
#include <vcpkg/sourceparagraph.h>
#include <vcpkg/paragraphs.h>
#include <vcpkg/dependencies.h>
#include <string>

using namespace vcpkg;
Expand Down Expand Up @@ -96,9 +97,9 @@ Features: a, b
Dependencies:
</description>
<packageTypes><packageType name="vcpkg"/></packageTypes>
</metadata>
</metadata>
<files><file src=")" PKGPATH R"(" target=""/></files>
</package>
</package>
)";
auto expected_lines = Strings::split(expected, '\n');
auto nuspec_lines = Strings::split(nuspec, '\n');
Expand All @@ -123,8 +124,14 @@ TEST_CASE ("XmlSerializer", "[XmlSerializer]")

xml = XmlSerializer();
xml.emit_declaration();
xml.start_complex_open_tag("a").text_attr("b", "<").text_attr("c", " ").finish_self_closing_complex_tag();
REQUIRE(xml.buf == R"(<?xml version="1.0" encoding="utf-8"?><a b="&lt;" c=" "/>)");
xml.start_complex_open_tag("a")
.text_attr("b", "<")
.text_attr("c", " ")
.finish_self_closing_complex_tag()
.line_break();
xml.simple_tag("d", "e");
REQUIRE(xml.buf == R"(<?xml version="1.0" encoding="utf-8"?><a b="&lt;" c=" "/>)"
"\n<d>e</d>");

xml = XmlSerializer();
xml.start_complex_open_tag("a").finish_complex_open_tag();
Expand All @@ -134,5 +141,72 @@ TEST_CASE ("XmlSerializer", "[XmlSerializer]")
xml.line_break();
xml.open_tag("a").line_break().line_break();
xml.close_tag("a").line_break().line_break();
REQUIRE(xml.buf == "\n<a>\n \n </a>\n\n");
}
REQUIRE(xml.buf == "\n<a>\n\n</a>\n\n");

xml = XmlSerializer();
xml.start_complex_open_tag("a")
.text_attr("b", "<")
.line_break()
.text_attr("c", " ")
.finish_complex_open_tag()
.line_break();
xml.simple_tag("d", "e").line_break();
REQUIRE(xml.buf == "<a b=\"&lt;\"\n c=\" \">\n <d>e</d>\n");
}

TEST_CASE ("generate_nuget_packages_config", "[generate_nuget_packages_config]")
{
Dependencies::ActionPlan plan;
auto packageconfig = generate_nuget_packages_config(plan);
REQUIRE(packageconfig == R"(<?xml version="1.0" encoding="utf-8"?>
<packages>
</packages>
)");

auto pghs = Paragraphs::parse_paragraphs(R"(
Source: zlib
Version: 1.5
Description: a spiffy compression library wrapper
)",
"<testdata>");
REQUIRE(pghs.has_value());
auto maybe_scf = SourceControlFile::parse_control_file(fs::path(), std::move(*pghs.get()));
REQUIRE(maybe_scf.has_value());
SourceControlFileLocation scfl{std::move(*maybe_scf.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
plan.install_actions[0].spec = PackageSpec("zlib", Triplet::X64_ANDROID);
plan.install_actions[0].source_control_file_location = scfl;
plan.install_actions[0].abi_info = Build::AbiInfo{};
plan.install_actions[0].abi_info.get()->package_abi = "packageabi";

packageconfig = generate_nuget_packages_config(plan);
REQUIRE(packageconfig == R"(<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="zlib_x64-android" version="1.5.0-packageabi"/>
</packages>
)");

auto pghs2 = Paragraphs::parse_paragraphs(R"(
Source: zlib2
Version: 1.52
Description: a spiffy compression library wrapper
)",
"<testdata>");
REQUIRE(pghs2.has_value());
auto maybe_scf2 = SourceControlFile::parse_control_file(fs::path(), std::move(*pghs2.get()));
REQUIRE(maybe_scf2.has_value());
SourceControlFileLocation scfl2{std::move(*maybe_scf2.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
plan.install_actions[1].spec = PackageSpec("zlib2", Triplet::X64_ANDROID);
plan.install_actions[1].source_control_file_location = scfl2;
plan.install_actions[1].abi_info = Build::AbiInfo{};
plan.install_actions[1].abi_info.get()->package_abi = "packageabi2";

packageconfig = generate_nuget_packages_config(plan);
REQUIRE(packageconfig == R"(<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="zlib_x64-android" version="1.5.0-packageabi"/>
<package id="zlib2_x64-android" version="1.52.0-packageabi2"/>
</packages>
)");
}
16 changes: 16 additions & 0 deletions toolsrc/src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,20 @@ namespace vcpkg::Files
message.push_back('\n');
System::print2(message);
}

fs::path combine(const fs::path& lhs, const fs::path& rhs)
{
#if VCPKG_USE_STD_FILESYSTEM
return lhs / rhs;
#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv
if (rhs.is_absolute())
{
return rhs;
}
else
{
return lhs / rhs;
}
#endif
}
}
Loading