Skip to content

reexec: add reexectest package#211

Open
thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:reexectest
Open

reexec: add reexectest package#211
thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:reexectest

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

This package allows using the reexec functionality to execute child processes as part of a test.

@thaJeztah thaJeztah force-pushed the reexectest branch 4 times, most recently from 1b6866e to fe0a892 Compare April 17, 2026 14:32
@thaJeztah thaJeztah marked this pull request as ready for review April 17, 2026 15:51
@thaJeztah thaJeztah force-pushed the reexectest branch 2 times, most recently from fccbfbe to 5e3a915 Compare June 5, 2026 07:39
This package allows using the reexec functionality to execute child
processes as part of a test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@vvoland

vvoland commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Hmm does it only work against test binaries created by go test -c, or does it also work with direct go test?

@thaJeztah

Copy link
Copy Markdown
Member Author

Yup, should still work; adding a quick patch to show the output;

diff --git a/reexec/reexectest/reexectest_test.go b/reexec/reexectest/reexectest_test.go
index c8dd5cd..1b57bf3 100644
--- a/reexec/reexectest/reexectest_test.go
+++ b/reexec/reexectest/reexectest_test.go
@@ -33,6 +33,8 @@ func TestRun(t *testing.T) {
                }
                if got := strings.TrimSpace(strings.TrimSuffix(string(out), "PASS\n")); got != expected {
                        t.Errorf("env-and-output output: got %q, want %q", got, expected)
+               } else {
+                       t.Logf("env-and-output output: got %q", out)
                }
        })

Then run;

go test -v -run TestRun
=== RUN   TestRun
=== RUN   TestRun/env-and-output
    reexectest_test.go:37: env-and-output output: got "child-env-and-output-ok\nPASS\n"
=== RUN   TestRun/exit-code
=== RUN   TestRun/args-passthrough
=== RUN   TestRun/context
--- PASS: TestRun (0.05s)
    --- PASS: TestRun/env-and-output (0.02s)
    --- PASS: TestRun/exit-code (0.01s)
    --- PASS: TestRun/args-passthrough (0.01s)
    --- PASS: TestRun/context (0.01s)
=== RUN   TestRunNonSubtest
--- PASS: TestRunNonSubtest (0.01s)
PASS
ok  	github.com/moby/sys/reexec/reexectest	0.401s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants