選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123 行
4.7KB

  1. # E07-S01 integration checks for scripts/prepare-disk.ps1.
  2. [CmdletBinding()]
  3. param()
  4. $ErrorActionPreference = "Stop"
  5. $project = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
  6. $repository = Split-Path $project -Parent
  7. $prepare = Join-Path $project "scripts\prepare-disk.ps1"
  8. $buildMinimal = Join-Path $project "scripts\build-minimal.ps1"
  9. $source = Join-Path $repository "vim\work.d81"
  10. $c1541 = "C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe"
  11. $testRoot = Join-Path $project "build\disk-test"
  12. $output = Join-Path $testRoot "newlang-test.d81"
  13. $examples = Join-Path $testRoot "examples"
  14. $testCompiler = Join-Path $testRoot "n128c-test.prg"
  15. $missing = Join-Path $testRoot "missing"
  16. if (-not (Test-Path -LiteralPath $prepare -PathType Leaf)) {
  17. throw "prepare-disk.ps1 not found"
  18. }
  19. if (-not (Test-Path -LiteralPath $source -PathType Leaf)) {
  20. throw "test source D81 not found: $source"
  21. }
  22. if (-not (Test-Path -LiteralPath $c1541 -PathType Leaf)) {
  23. throw "test c1541 not found: $c1541"
  24. }
  25. New-Item -ItemType Directory -Force -Path $examples | Out-Null
  26. [IO.File]::WriteAllText((Join-Path $examples "demo.n8"),
  27. "program Main`n print `"Nova128`"`nend program`n",
  28. [Text.UTF8Encoding]::new($false))
  29. # E01-S01 is this story's completed dependency and provides a known-good PRG.
  30. & $buildMinimal | Out-Host
  31. $minimal = Join-Path $project "build\minimal.prg"
  32. Copy-Item -LiteralPath $minimal -Destination $testCompiler -Force
  33. $sourceHashBefore = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash
  34. $first = & $prepare -SourceImage $source -OutputImage $output -C1541Path $c1541 `
  35. -CompilerPrg $testCompiler -ProbePrg $minimal -ExamplesDirectory $examples `
  36. -RequireCompiler
  37. if (-not (Test-Path -LiteralPath $output -PathType Leaf)) {
  38. throw "prepare-disk did not create the disposable image"
  39. }
  40. $firstHash = (Get-FileHash -LiteralPath $output -Algorithm SHA256).Hash
  41. $listing = (& $c1541 $output -list 2>&1) -join "`n"
  42. foreach ($expected in @(
  43. '(?im)"n128c"\s+prg\s*$',
  44. '(?im)"n128probe"\s+prg\s*$',
  45. '(?im)"demo\.n8"\s+seq\s*$')) {
  46. if ($listing -notmatch $expected) {
  47. throw "prepared directory lacks expected entry $expected`n$listing"
  48. }
  49. }
  50. # Damage only the generated output, then prove a rebuild returns to the exact
  51. # same bytes from the clean source image.
  52. [IO.File]::WriteAllBytes($output, [byte[]](1, 2, 3, 4))
  53. $second = & $prepare -SourceImage $source -OutputImage $output -C1541Path $c1541 `
  54. -CompilerPrg $testCompiler -ProbePrg $minimal -ExamplesDirectory $examples `
  55. -RequireCompiler
  56. $secondHash = (Get-FileHash -LiteralPath $output -Algorithm SHA256).Hash
  57. if ($firstHash -ne $secondHash) {
  58. throw "two clean prepares produced different D81 hashes"
  59. }
  60. $sourceHashAfter = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash
  61. if ($sourceHashAfter -ne $sourceHashBefore) {
  62. throw "source D81 hash changed during prepare test"
  63. }
  64. # Optional, not-yet-built artifacts must be skipped without preventing a clean
  65. # copy. This deliberately uses absent compiler, probe, and examples paths.
  66. $optionalOutput = Join-Path $testRoot "optional-only.d81"
  67. $optional = & $prepare -SourceImage $source -OutputImage $optionalOutput `
  68. -C1541Path $c1541 -CompilerPrg (Join-Path $missing "n128c.prg") `
  69. -ProbePrg (Join-Path $missing "probe.prg") `
  70. -ExamplesDirectory (Join-Path $missing "examples") 3>&1
  71. if (-not (Test-Path -LiteralPath $optionalOutput -PathType Leaf)) {
  72. throw "missing optional artifacts prevented creation of the copied D81"
  73. }
  74. function Assert-FailsWith {
  75. param(
  76. [Parameter(Mandatory = $true)][scriptblock]$Action,
  77. [Parameter(Mandatory = $true)][string]$Pattern
  78. )
  79. $caught = $null
  80. try {
  81. & $Action
  82. } catch {
  83. $caught = $_.Exception.Message
  84. }
  85. if ($null -eq $caught) {
  86. throw "expected failure matching '$Pattern', but the command succeeded"
  87. }
  88. if ($caught -notmatch $Pattern) {
  89. throw "failure '$caught' did not match '$Pattern'"
  90. }
  91. }
  92. Assert-FailsWith -Pattern 'source D81 not found' -Action {
  93. & $prepare -SourceImage (Join-Path $missing "work.d81") `
  94. -OutputImage (Join-Path $testRoot "never-source.d81") `
  95. -C1541Path $c1541
  96. }
  97. Assert-FailsWith -Pattern 'c1541 tool not found' -Action {
  98. & $prepare -SourceImage $source `
  99. -OutputImage (Join-Path $testRoot "never-tool.d81") `
  100. -C1541Path (Join-Path $missing "c1541.exe")
  101. }
  102. Assert-FailsWith -Pattern 'must not be the source' -Action {
  103. & $prepare -SourceImage $source -OutputImage $source -C1541Path $c1541
  104. }
  105. Write-Host "prepare-disk tests passed"
  106. Write-Host "source SHA-256 unchanged: $sourceHashAfter"
  107. Write-Host "deterministic output SHA-256: $secondHash"
  108. Write-Host "directory entries verified: n128c, n128probe, demo.n8"

Powered by TurnKey Linux.