Skip to content

Commit

Permalink
Fix end to end tests writing into the source tree. (#1106)
Browse files Browse the repository at this point in the history
* Fix overlays test writing to the source tree.

* Fix patterns test writing into the source tree.
  • Loading branch information
BillyONeal authored Jun 22, 2023
1 parent 7e3b1a7 commit add000a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"overlay-ports": [ "./azure-pipelines/e2e_projects/overlays-project-with-config/config-overlays" ],
"overlay-ports": [ "./azure-pipelines/e2e_projects/overlays-project-with-config/config-overlays/nonexistent" ],
"overlay-triplets": [ 123 ]
}
14 changes: 9 additions & 5 deletions azure-pipelines/end-to-end-tests-dir/overlays.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

# Tests a simple project with overlay ports and triplets configured on a vcpkg-configuration.json file
$e2eProjects = "$PSScriptRoot/../e2e_projects"
Copy-Item -Recurse -LiteralPath @(
"$PSScriptRoot/../e2e_projects/overlays-project-with-config",
"$PSScriptRoot/../e2e_projects/overlays-project-config-embedded",
"$PSScriptRoot/../e2e_projects/overlays-bad-paths"
) $TestingRoot

$manifestRoot = "$e2eProjects/overlays-project-with-config"
$manifestRoot = "$TestingRoot/overlays-project-with-config"
$env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env-overlays"

Run-Vcpkg install --x-manifest-root=$manifestRoot `
Expand All @@ -13,7 +17,7 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
Throw-IfFailed

# Tests overlays configured in env and cli on a project with configuration embedded on the manifest file
$manifestRoot = "$e2eProjects/overlays-project-config-embedded"
$manifestRoot = "$TestingRoot/overlays-project-config-embedded"
$env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env-overlays"
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-ports=$manifestRoot/cli-overlays `
Expand All @@ -22,15 +26,15 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
Throw-IfFailed

# Config with bad paths
$manifestRoot = "$e2eProjects/overlays-bad-paths"
$manifestRoot = "$TestingRoot/overlays-bad-paths"
$env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env_overlays"
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-triplets=$manifestRoot/my-triplets `
--x-install-root=$installRoot
Throw-IfNotFailed

# Test overlay_triplet paths remain relative to the manifest root after x-update-baseline
$manifestRoot = "$e2eProjects/overlays-project-with-config"
$manifestRoot = "$TestingRoot/overlays-project-with-config"
$configurationBefore = Get-Content "$manifestRoot/vcpkg-configuration.json" | ConvertFrom-Json
Run-Vcpkg x-update-baseline --x-manifest-root=$manifestRoot
$configurationAfter = Get-Content "$manifestRoot/vcpkg-configuration.json" | ConvertFrom-Json
Expand Down
148 changes: 79 additions & 69 deletions azure-pipelines/end-to-end-tests-dir/patterns.ps1
Original file line number Diff line number Diff line change
@@ -1,84 +1,94 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

### <Initialize registry>
# Creates a git registry to run the e2e tests on
$e2eProjects = "$PSScriptRoot/../e2e_projects"
$manifestRoot = "$e2eProjects/registries-package-patterns"
$e2eRegistryPath = "$PSScriptRoot/../e2e_registry".Replace('\', '\\')
Push-Location $e2eRegistryPath
try
{
Write-Host "Initializing test registry"
if (Test-Path "$e2eRegistryPath/.git")
{
Remove-Item -Recurse -Force "$e2eRegistryPath/.git"
}

Copy-Item -Recurse -LiteralPath @(
"$PSScriptRoot/../e2e_projects/registries-package-patterns",
"$PSScriptRoot/../e2e_registry"
) $WorkingRoot

$gitConfig = @(
'-c', 'user.name=Nobody',
'-c', 'user.email=nobody@example.com',
'-c', 'core.autocrlf=false'
)
$manifestRoot = "$WorkingRoot/registries-package-patterns"
$e2eRegistryPath = "$WorkingRoot/e2e_registry".Replace('\', '\\')
Push-Location $e2eRegistryPath
### <Initialize registry>
# Creates a git registry to run the e2e tests on
try
{
Write-Host "Initializing test registry"
if (Test-Path "$e2eRegistryPath/.git")
{
Remove-Item -Recurse -Force "$e2eRegistryPath/.git"
}


git @gitConfig init . | Out-Null
Throw-IfFailed
git @gitConfig add -A | Out-Null
Throw-IfFailed
git @gitConfig commit -m "initial commit" | Out-Null
Throw-IfFailed
$e2eRegistryBaseline = git rev-parse HEAD
Throw-IfFailed
}
finally
{
Pop-Location
}
### </Initialize Registry>
$gitConfig = @(
'-c', 'user.name=Nobody',
'-c', 'user.email=nobody@example.com',
'-c', 'core.autocrlf=false'
)

$commonArgs += @("--x-manifest-root=$manifestRoot")
git @gitConfig init . | Out-Null
Throw-IfFailed
git @gitConfig add -A | Out-Null
Throw-IfFailed
git @gitConfig commit -m "initial commit" | Out-Null
Throw-IfFailed
$e2eRegistryBaseline = git rev-parse HEAD
Throw-IfFailed
}
finally
{
Pop-Location
}
### </Initialize Registry>

# [patterns] No patterns (no default)
Write-Host "[patterns] No patterns (no default)"
$inFile = "$manifestRoot/no-patterns.json.in"
(Get-Content -Path "$inFile").Replace("`$E2ERegistryPath", $e2eRegistryPath).Replace("`$E2ERegistryBaseline", $e2eRegistryBaseline) `
| Out-File "$manifestRoot/vcpkg.json"
function Update-VcpkgJson {
param($PreReplacementName)
$content = Get-Content -LiteralPath "$manifestRoot/$PreReplacementName"
$content = $content.Replace('$E2ERegistryPath', $e2eRegistryPath)
$content = $content.Replace('$E2ERegistryBaseline', $e2eRegistryBaseline)
Set-Content -LiteralPath "$manifestRoot/vcpkg.json" -Value $content
}

Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot
$commonArgs += @("--x-manifest-root=$manifestRoot")

# [patterns] Patterns only (no default)
Write-Host "[patterns] Patterns only (no default)"
$inFile = "$manifestRoot/only-patterns.json.in"
(Get-Content -Path "$inFile").Replace("`$E2ERegistryPath", $e2eRegistryPath).Replace("`$E2ERegistryBaseline", $e2eRegistryBaseline) `
| Out-File "$manifestRoot/vcpkg.json"
# [patterns] No patterns (no default)
Write-Host "[patterns] No patterns (no default)"
Update-VcpkgJson 'no-patterns.json.in'
Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot

Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot
# [patterns] Patterns only (no default)
Write-Host "[patterns] Patterns only (no default)"
Update-VcpkgJson 'only-patterns.json.in'
Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot

# [patterns] Patterns with default
Write-Host "[patterns] Patterns with default"
$inFile = "$manifestRoot/with-default.json.in"
(Get-Content -Path "$inFile").Replace("`$E2ERegistryPath", $e2eRegistryPath).Replace("`$E2ERegistryBaseline", $e2eRegistryBaseline) `
| Out-File "$manifestRoot/vcpkg.json"
# [patterns] Patterns with default
Write-Host "[patterns] Patterns with default"
Update-VcpkgJson 'with-default.json.in'
Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot

Run-Vcpkg -EndToEndTestSilent @commonArgs install | Out-Null
Throw-IfFailed
Refresh-TestRoot

# [patterns] Repeated patterns
Write-Host "[patterns] Repeated patterns"
$inFile = "$manifestRoot/with-redeclaration.json.in"
(Get-Content -Path "$inFile").Replace("`$E2ERegistryPath", $e2eRegistryPath).Replace("`$E2ERegistryBaseline", $e2eRegistryBaseline) `
| Out-File "$manifestRoot/vcpkg.json"

$out = Run-VcpkgAndCaptureOutput -EndToEndTestSilent @commonArgs install
Throw-IfFailed
if ($out -notmatch "redeclarations will be ignored")
# [patterns] Repeated patterns
Write-Host "[patterns] Repeated patterns"
Update-VcpkgJson 'with-redeclaration.json.in'
$out = Run-VcpkgAndCaptureOutput -EndToEndTestSilent @commonArgs install
Throw-IfFailed
if ($out -notmatch "redeclarations will be ignored")
{
$out
throw "Expected warning about redeclaration"
}
Refresh-TestRoot
}
finally
{
$out
throw "Expected warning about redeclaration"
Remove-Item -Recurse -Force -LiteralPath @(
"$WorkingRoot/registries-package-patterns",
"$WorkingRoot/e2e_registry"
) -ErrorAction SilentlyContinue
}
Refresh-TestRoot

0 comments on commit add000a

Please sign in to comment.