返回 DeepSeek-Reasonix
diff_test.go
根目录 / cmd / e2ebench / diff_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8 )
9
10 func TestRunTestsAllowsStaticEnvAssignment(t *testing.T) {
11 repo := t.TempDir()
12 writeE2EFile(t, filepath.Join(repo, "go.mod"), "module example.com/e2ebenchtest\n\ngo 1.23\n")
13 writeE2EFile(t, filepath.Join(repo, "env_test.go"), `package e2ebenchtest
14
15 import (
16 "os"
17 "testing"
18 )
19
20 func TestEnv(t *testing.T) {
21 if got := os.Getenv("REASONIX_E2E_ENV"); got != "ok" {
22 t.Fatalf("REASONIX_E2E_ENV = %q", got)
23 }
24 }
25 `)
26
27 ok, out := runTests(repo, "GOWORK=off REASONIX_E2E_ENV=ok go test", []string{"./..."})
28 if !ok {
29 t.Fatalf("runTests failed:\n%s", out)
30 }
31 }
32
33 func TestRunTestsRejectsDynamicEnvAssignment(t *testing.T) {
34 ok, out := runTests(t.TempDir(), "REASONIX_E2E_ENV=$(echo ok) go test", []string{"./..."})
35 if ok {
36 t.Fatal("runTests accepted dynamic env assignment")
37 }
38 if !strings.Contains(out, "invalid test command: shell expansion") {
39 t.Fatalf("output = %q, want shell expansion rejection", out)
40 }
41 }
42
43 func writeE2EFile(t *testing.T, path, content string) {
44 t.Helper()
45 if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
46 t.Fatalf("write %s: %v", path, err)
47 }
48 }
49
49 lines GO