From 464a69ae87f8b36c40b429de0e9e283a74bf2897 Mon Sep 17 00:00:00 2001 From: William Martin Date: Tue, 8 Oct 2024 15:12:13 +0200 Subject: [PATCH] Use stdout2env in PR acceptance tests --- acceptance/pr_test.go | 17 +++++++++++++---- acceptance/testdata/pr/pr-checkout.txt | 3 ++- acceptance/testdata/pr/pr-view.txt | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/acceptance/pr_test.go b/acceptance/pr_test.go index 38f3e1f79..563526f6f 100644 --- a/acceptance/pr_test.go +++ b/acceptance/pr_test.go @@ -58,11 +58,20 @@ var sharedSetup = func(ts *testscript.Env) error { var sharedCmds = map[string]func(ts *testscript.TestScript, neg bool, args []string){ "defer": func(ts *testscript.TestScript, neg bool, args []string) { ts.Defer(func() { - if err := ts.Exec(args[0], args[1:]...); err != nil { - ts.Fatalf("deferred command failed: %v", err) - } + ts.Check(ts.Exec(args[0], args[1:]...)) }) - }} + }, + "stdout2env": func(ts *testscript.TestScript, neg bool, args []string) { + if neg { + ts.Fatalf("unsupported: ! stdout2env") + } + if len(args) != 1 { + ts.Fatalf("usage: stdout2env name") + } + + ts.Setenv(args[0], strings.TrimRight(ts.ReadFile("stdout"), "\n")) + }, +} var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") diff --git a/acceptance/testdata/pr/pr-checkout.txt b/acceptance/testdata/pr/pr-checkout.txt index d02c42076..4cfe96c1a 100644 --- a/acceptance/testdata/pr/pr-checkout.txt +++ b/acceptance/testdata/pr/pr-checkout.txt @@ -18,6 +18,7 @@ exec git push -u origin feature-branch # Create the PR exec gh pr create --title 'Feature Title' --body 'Feature Body' +stdout2env PR_URL # Remove the local branch exec git checkout main @@ -25,5 +26,5 @@ exec git branch -D feature-branch stdout 'Deleted branch feature-branch' # Checkout the PR -exec gh pr checkout 1 +exec gh pr checkout $PR_URL stderr 'Switched to a new branch ''feature-branch''' diff --git a/acceptance/testdata/pr/pr-view.txt b/acceptance/testdata/pr/pr-view.txt index c9dfcd3a6..6166d15ad 100644 --- a/acceptance/testdata/pr/pr-view.txt +++ b/acceptance/testdata/pr/pr-view.txt @@ -18,7 +18,8 @@ exec git push -u origin feature-branch # Create the PR exec gh pr create --title 'Feature Title' --body 'Feature Body' +stdout2env PR_URL # View the PR -exec gh pr view 1 +exec gh pr view $PR_URL stdout 'Feature Title'