|
| 1 | +using Test |
| 2 | + |
| 3 | +""" |
| 4 | + dry_run_release(top_header, older_header) -> (exit_code, stderr_text) |
| 5 | +
|
| 6 | +Run `bin/release --dry-run` against a throwaway repository at version 5.0.0 |
| 7 | +whose `CHANGELOG.md` holds a section under each of the two headers, with a stub |
| 8 | +`gh` on `PATH` so nothing reaches GitHub. |
| 9 | +""" |
| 10 | +function dry_run_release(top_header, older_header) |
| 11 | + root = mktempdir() |
| 12 | + repo = mkpath(joinpath(root, "repo")) |
| 13 | + write(joinpath(repo, "Project.toml"), """ |
| 14 | + name = "Fixture" |
| 15 | + version = "5.0.0" |
| 16 | + """) |
| 17 | + write(joinpath(repo, "CHANGELOG.md"), """ |
| 18 | + # Changelog |
| 19 | +
|
| 20 | + $top_header |
| 21 | +
|
| 22 | + ### Added |
| 23 | +
|
| 24 | + - the newer note |
| 25 | +
|
| 26 | + $older_header |
| 27 | +
|
| 28 | + ### Fixed |
| 29 | +
|
| 30 | + - the older note |
| 31 | + """) |
| 32 | + run(`git -C $repo init --quiet`) |
| 33 | + run(`git -C $repo add --all`) |
| 34 | + run(`git -C $repo -c user.email=fixture@example.com -c user.name=Fixture |
| 35 | + commit --quiet -m "fixture"`) |
| 36 | + |
| 37 | + stub = mkpath(joinpath(root, "stub")) |
| 38 | + gh_stub = joinpath(stub, "gh") |
| 39 | + write(gh_stub, """ |
| 40 | + #!/bin/bash |
| 41 | + case "\$1" in |
| 42 | + repo) echo "OpenSourceAWE/Fixture" ;; |
| 43 | + esac |
| 44 | + """) |
| 45 | + chmod(gh_stub, 0o755) |
| 46 | + |
| 47 | + script = normpath(joinpath(@__DIR__, "..", "..", "bin", "release")) |
| 48 | + stderr_file = joinpath(root, "stderr.txt") |
| 49 | + env = copy(ENV) |
| 50 | + env["PATH"] = stub * ":" * ENV["PATH"] |
| 51 | + command = setenv(`bash $script --dry-run`, env; dir=repo) |
| 52 | + process = run(pipeline(ignorestatus(command); stdout=devnull, stderr=stderr_file)) |
| 53 | + return process.exitcode, read(stderr_file, String) |
| 54 | +end |
| 55 | + |
| 56 | +@testset "bin/release" begin |
| 57 | + @testset "release refuses an unversioned top section above the last release" begin |
| 58 | + exit_code, stderr_text = |
| 59 | + dry_run_release("## Unreleased", "## Fixture v5.0.0 2026-09-07") |
| 60 | + @test exit_code != 0 |
| 61 | + @test occursin("Version mismatch", stderr_text) |
| 62 | + end |
| 63 | + |
| 64 | + @testset "release accepts a top section naming the package version" begin |
| 65 | + exit_code, stderr_text = |
| 66 | + dry_run_release("## Fixture v5.0.0 2026-09-07", "## Fixture v4.3.1 2026-08-01") |
| 67 | + @test exit_code == 0 |
| 68 | + @test isempty(stderr_text) |
| 69 | + end |
| 70 | +end |
0 commit comments