Skip to content

Commit

Permalink
Move last reference to VcpkgPaths from unit tests into e2e test (#324)
Browse files Browse the repository at this point in the history
* Move last reference to VcpkgPaths from unit tests into e2e test

* Remove VCPKG_ROOT from unit tests in pipelines

* Address CR feedback
  • Loading branch information
ras0219-msft authored Jan 27, 2022
1 parent 23a5f63 commit e49443d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 58 deletions.
20 changes: 20 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/manifest-reserialize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
. "$PSScriptRoot/../end-to-end-tests-prelude.ps1"

Write-Trace "test re-serializing every manifest"
$manifestDir = "$TestingRoot/manifest-dir"
New-Item -Path $manifestDir -ItemType Directory | Out-Null

$ports = Get-ChildItem "$env:VCPKG_ROOT/ports"

$ports | % {
if (Test-Path "$_/vcpkg.json") {
Copy-Item "$_/vcpkg.json" "$manifestDir" | Out-Null
$x = Get-Content "$manifestDir/vcpkg.json" -Raw
Run-Vcpkg -EndToEndTestSilent format-manifest "$manifestDir/vcpkg.json" | Out-Null
Throw-IfFailed "$_/vcpkg.json"
$y = Get-Content "$manifestDir/vcpkg.json" -Raw
if ($x -ne $y) {
throw "Expected formatting manifest $_/vcpkg.json to cause no modifications"
}
}
}
11 changes: 9 additions & 2 deletions azure-pipelines/end-to-end-tests-prelude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ function Require-FileNotExists {
}

function Throw-IfFailed {
[CmdletBinding()]
Param(
[string]$Message = ""
)
if ($LASTEXITCODE -ne 0) {
Write-Stack
throw "'$Script:CurrentTest' had a step with a nonzero exit code"
throw "'$Script:CurrentTest' had a step with a nonzero exit code: $Message"
}
}

Expand All @@ -89,11 +93,14 @@ function Write-Trace ([string]$text) {

function Run-Vcpkg {
Param(
[Parameter(Mandatory = $false)]
[Switch]$EndToEndTestSilent,

[Parameter(ValueFromRemainingArguments)]
[string[]]$TestArgs
)
$Script:CurrentTest = "$VcpkgExe $($testArgs -join ' ')"
Write-Host $Script:CurrentTest
if (!$EndToEndTestSilent) { Write-Host $Script:CurrentTest }
& $VcpkgExe @testArgs
}

Expand Down
9 changes: 8 additions & 1 deletion azure-pipelines/pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
failOnStderr: true
- bash: build.amd64.debug/vcpkg-test
displayName: 'Run vcpkg tests'
env:
VCPKG_ROOT: UNIT_TESTS_SHOULD_NOT_USE_VCPKG_ROOT
- task: PowerShell@2
displayName: 'Run vcpkg end-to-end tests'
inputs:
Expand Down Expand Up @@ -93,7 +95,7 @@ jobs:
git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT -n
git -C "$env:VCPKG_ROOT" checkout $sha
- task: CmdLine@2
displayName: "Build vcpkg with CMake, and Run Tests"
displayName: "Build vcpkg with CMake"
inputs:
script: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=x86 -host_arch=x86
Expand All @@ -102,6 +104,11 @@ jobs:
ninja.exe -C build.x86.debug
build.x86.debug\vcpkg-test.exe
failOnStderr: true
- script: build.x86.debug\vcpkg-test.exe
displayName: "Run vcpkg tests"
failOnStderr: true
env:
VCPKG_ROOT: UNIT_TESTS_SHOULD_NOT_USE_VCPKG_ROOT
- task: PowerShell@2
displayName: 'Run vcpkg end-to-end tests'
inputs:
Expand Down
3 changes: 3 additions & 0 deletions src/vcpkg-test/catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ int main(int argc, char** argv)
{
vcpkg::msg::threadunsafe_initialize_context();
if (vcpkg::get_environment_variable("VCPKG_DEBUG").value_or("") == "1") vcpkg::Debug::g_debugging = true;
// We set VCPKG_ROOT to an invalid value to ensure unit tests do not attempt to instantiate VcpkgRoot
vcpkg::set_environment_variable("VCPKG_ROOT", "VCPKG_TESTS_SHOULD_NOT_USE_VCPKG_ROOT");

return Catch::Session().run(argc, argv);
}
55 changes: 0 additions & 55 deletions src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,58 +969,3 @@ TEST_CASE ("SourceParagraph manifest non-string supports", "[manifests]")
true);
REQUIRE_FALSE(m_pgh.has_value());
}

TEST_CASE ("Serialize all the ports", "[all-manifests]")
{
std::vector<std::string> args_list = {"format-manifest"};
auto& fs = get_real_filesystem();
auto args = VcpkgCmdArguments::create_from_arg_sequence(args_list.data(), args_list.data() + args_list.size());
args.imbue_from_environment();
VcpkgPaths paths{fs, args};

std::vector<SourceControlFile> scfs;

for (auto&& dir : fs.get_directories_non_recursive(paths.builtin_ports_directory(), VCPKG_LINE_INFO))
{
const auto control = dir / "CONTROL";
const auto manifest = dir / "vcpkg.json";
if (fs.exists(control, IgnoreErrors{}))
{
INFO(control.native());
auto contents = fs.read_contents(control, VCPKG_LINE_INFO);
auto pghs = Paragraphs::parse_paragraphs(contents, control);
REQUIRE(pghs);

auto scf = SourceControlFile::parse_control_file(control, std::move(pghs).value_or_exit(VCPKG_LINE_INFO));
if (!scf)
{
INFO(scf.error()->name);
INFO(scf.error()->error);
REQUIRE(scf);
}

scfs.push_back(std::move(*scf.value_or_exit(VCPKG_LINE_INFO)));
}
else if (fs.exists(manifest, IgnoreErrors{}))
{
std::error_code ec;
auto contents = Json::parse_file(fs, manifest, ec);
REQUIRE_FALSE(ec);
REQUIRE(contents);

auto scf = SourceControlFile::parse_manifest_object(manifest,
contents.value_or_exit(VCPKG_LINE_INFO).first.object());
REQUIRE(scf);

scfs.push_back(std::move(*scf.value_or_exit(VCPKG_LINE_INFO)));
}
}

for (auto& scf : scfs)
{
auto serialized = serialize_manifest(scf);
auto serialized_scf = SourceControlFile::parse_manifest_object({}, serialized).value_or_exit(VCPKG_LINE_INFO);

REQUIRE(*serialized_scf == scf);
}
}

0 comments on commit e49443d

Please sign in to comment.