Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

125 Zeilen
5.3KB

  1. # E08-S01: harness self-tests. These prove the mechanics without starting an
  2. # emulator: fresh build directories, a wall-clock limit, machine-readable
  3. # results, artifact comparison, and a failed run that names the suite and its
  4. # observed signature.
  5. [CmdletBinding()]
  6. param()
  7. $ErrorActionPreference = "Stop"
  8. $project = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
  9. $harness = Join-Path $PSScriptRoot "run-regression.ps1"
  10. $root = Join-Path $project "build\regression-selftest"
  11. $suites = Join-Path $root "suites"
  12. $buildRoot = Join-Path $root "build"
  13. $baseline = Join-Path $root "baseline.json"
  14. $results = Join-Path $root "results.json"
  15. $manifest = Join-Path $root "suites.ps1"
  16. if (Test-Path -LiteralPath $root) { Remove-Item -LiteralPath $root -Recurse -Force }
  17. New-Item -ItemType Directory -Force -Path $suites, $buildRoot | Out-Null
  18. function Write-Suite([string]$Name, [string]$Body) {
  19. [IO.File]::WriteAllText((Join-Path $suites $Name), $Body,
  20. [Text.UTF8Encoding]::new($false))
  21. }
  22. # A passing suite writes one artifact and prints a stable success marker.
  23. Write-Suite "ok.ps1" @'
  24. $out = Join-Path (Split-Path $PSScriptRoot -Parent) "build\self-ok"
  25. New-Item -ItemType Directory -Force -Path $out | Out-Null
  26. [IO.File]::WriteAllBytes((Join-Path $out "self.prg"), [byte[]](1, 2, 3, 4))
  27. Write-Host "verified self ok"
  28. exit 0
  29. '@
  30. # A failing suite prints a diagnosis the harness must surface.
  31. Write-Suite "bad.ps1" @'
  32. Write-Host "self fixture ALPHA differs at token 7 (observed signature DEAD)"
  33. exit 3
  34. '@
  35. # A hanging suite must be stopped by the wall-clock limit.
  36. Write-Suite "slow.ps1" @'
  37. Start-Sleep -Seconds 60
  38. Write-Host "should never finish"
  39. exit 0
  40. '@
  41. # A suite whose artifact content changes between runs.
  42. Write-Suite "changed.ps1" @'
  43. param()
  44. $out = Join-Path (Split-Path $PSScriptRoot -Parent) "build\self-changed"
  45. New-Item -ItemType Directory -Force -Path $out | Out-Null
  46. $value = 5
  47. if (Test-Path (Join-Path $out "bump.txt")) { $value = 6 }
  48. [IO.File]::WriteAllText((Join-Path $out "bump.txt"), "$value")
  49. [IO.File]::WriteAllBytes((Join-Path $out "self.err"), [byte[]]$value)
  50. Write-Host "verified self changed"
  51. exit 0
  52. '@
  53. [IO.File]::WriteAllText($manifest, @'
  54. @(
  55. @{ Name = "ok"; Script = "build\regression-selftest\suites\ok.ps1"; BuildDir = "self-ok"; Timeout = 60; Success = "verified self ok"; Artifacts = @("*.prg") }
  56. @{ Name = "bad"; Script = "build\regression-selftest\suites\bad.ps1"; Timeout = 60 }
  57. @{ Name = "slow"; Script = "build\regression-selftest\suites\slow.ps1"; Timeout = 3 }
  58. @{ Name = "changed"; Script = "build\regression-selftest\suites\changed.ps1"; BuildDir = "self-changed"; Timeout = 60; Artifacts = @("*.err") }
  59. )
  60. '@, [Text.UTF8Encoding]::new($false))
  61. function Invoke-Harness([string[]]$Extra) {
  62. $arguments = @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ('"' + $harness + '"'),
  63. "-Manifest", ('"' + $manifest + '"'), "-BuildRoot", ('"' + $buildRoot + '"'),
  64. "-Baseline", ('"' + $baseline + '"'), "-Results", ('"' + $results + '"')) + $Extra
  65. $output = & (Get-Command powershell).Source @arguments 2>&1 | Out-String
  66. return @{ Output = $output; Code = $LASTEXITCODE }
  67. }
  68. function Get-Report { Get-Content -Raw -LiteralPath $results | ConvertFrom-Json }
  69. function Get-Entry([object]$Report, [string]$Name) {
  70. return $Report.suites | Where-Object { $_.name -eq $Name }
  71. }
  72. # 1: passing suite, artifact recorded, baseline written and matched on a rerun.
  73. $first = Invoke-Harness @("-UpdateBaseline")
  74. if (-not (Test-Path -LiteralPath $results)) { throw "first harness run wrote no results:`n$($first.Output)" }
  75. $report = Get-Report
  76. if ($report.passed -ne 2) { throw "expected 2 passing suites, got $($report.passed)" }
  77. $ok = Get-Entry $report "ok"
  78. if ($ok.artifacts.Count -ne 1 -or $ok.artifacts[0].status -ne "new") {
  79. throw "the passing suite did not record its artifact"
  80. }
  81. if (-not (Test-Path -LiteralPath $baseline)) { throw "-UpdateBaseline wrote no baseline" }
  82. $second = Invoke-Harness @("-NoFresh")
  83. $ok = Get-Entry (Get-Report) "ok"
  84. if ($ok.artifacts[0].status -ne "match") {
  85. throw "a rerun did not match the recorded artifact:`n$($second.Output)"
  86. }
  87. # 2: a failing suite names the suite and the observed signature.
  88. $bad = Get-Entry (Get-Report) "bad"
  89. if ($bad.status -ne "fail" -or $bad.signature -notmatch "ALPHA differs") {
  90. throw "the failing suite did not report its signature: $($bad.signature)"
  91. }
  92. $slow = Get-Entry (Get-Report) "slow"
  93. if ($slow.status -ne "fail" -or -not $slow.timedOut) {
  94. throw "the hanging suite was not stopped by the time limit"
  95. }
  96. if ($second.Code -eq 0) { throw "the harness reported success with failing suites" }
  97. # 3: an artifact whose bytes change is reported as changed on the next run.
  98. $third = Invoke-Harness @("-NoFresh")
  99. $changed = Get-Entry (Get-Report) "changed"
  100. if ($third.Code -eq 0 -or $changed.artifacts[0].status -ne "changed") {
  101. throw "a changed artifact was not detected:`n$($third.Output)"
  102. }
  103. # 4: results are machine-readable and identify the suite and its log.
  104. if (-not $report.startedAt -or -not $report.finishedAt) { throw "results lack timestamps" }
  105. foreach ($entry in $report.suites) {
  106. if (-not $entry.log -or -not (Test-Path -LiteralPath $entry.log)) {
  107. throw "suite $($entry.name) has no captured log"
  108. }
  109. }
  110. Write-Host "regression harness tests passed"
  111. Write-Host "pass/fail/timeout/artifact-change detection, JSON results, captured logs"

Powered by TurnKey Linux.