diff --git a/main_test.go b/main_test.go index c54f8cc..8e33e4c 100644 --- a/main_test.go +++ b/main_test.go @@ -9,8 +9,8 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "runtime" + "strings" "testing" "github.com/rogpeppe/go-internal/gotooltest" @@ -47,8 +47,8 @@ func TestScripts(t *testing.T) { return nil }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "bingrep": bingrep, - "bincmp": bincmp, + "binsubstr": binsubstr, + "bincmp": bincmp, }, UpdateScripts: *update, } @@ -58,19 +58,17 @@ func TestScripts(t *testing.T) { testscript.Run(t, p) } -func bingrep(ts *testscript.TestScript, neg bool, args []string) { +func binsubstr(ts *testscript.TestScript, neg bool, args []string) { if len(args) < 2 { - ts.Fatalf("usage: bingrep file pattern...") + ts.Fatalf("usage: binsubstr file substr...") } data := ts.ReadFile(args[0]) - for _, pattern := range args[1:] { - rx, err := regexp.Compile(pattern) - ts.Check(err) - match := rx.MatchString(data) + for _, substr := range args[1:] { + match := strings.Contains(data, substr) if match && neg { - ts.Fatalf("unexpected match for %q in %s", pattern, args[0]) + ts.Fatalf("unexpected match for %q in %s", substr, args[0]) } else if !match && !neg { - ts.Fatalf("expected match for %q in %s", pattern, args[0]) + ts.Fatalf("expected match for %q in %s", substr, args[0]) } } } diff --git a/testdata/scripts/basic.txt b/testdata/scripts/basic.txt index d9fd2be..33aea0a 100644 --- a/testdata/scripts/basic.txt +++ b/testdata/scripts/basic.txt @@ -10,8 +10,8 @@ cmp stderr main.stderr # The default build includes full non-trimmed paths, as well as our names. # Only check $WORK on non-windows, because it's difficult to do it there. -bingrep main$exe 'globalVar' 'globalFunc' -[!windows] bingrep main$exe ${WORK@R} +binsubstr main$exe 'globalVar' 'globalFunc' +[!windows] binsubstr main$exe ${WORK@R} # Check that we fail if the user forgot -trimpath. ! exec go build -a -toolexec=garble main.go @@ -26,7 +26,7 @@ cmp stderr main.stderr [!windows] [exec:readelf] ! stdout 'debug_info' [!windows] [exec:readelf] ! stdout '\.symtab' -! bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc' +! binsubstr main$exe ${WORK@R} 'globalVar' 'globalFunc' [short] stop # checking that the build is reproducible is slow @@ -35,7 +35,7 @@ cmp stderr main.stderr cp main$exe main_old$exe rm main$exe garble build main.go -! bingrep main$exe 'globalVar' +! binsubstr main$exe 'globalVar' bincmp main$exe main_old$exe -- main.go -- diff --git a/testdata/scripts/implement.txt b/testdata/scripts/implement.txt index 7a605a8..a1eaedf 100644 --- a/testdata/scripts/implement.txt +++ b/testdata/scripts/implement.txt @@ -2,7 +2,7 @@ garble build main.go exec ./main cmp stdout main.stdout -! bingrep main$exe 'unexportedMethod' +! binsubstr main$exe 'unexportedMethod' -- main.go -- package main diff --git a/testdata/scripts/imports.txt b/testdata/scripts/imports.txt index fbfb0db..5f9e395 100644 --- a/testdata/scripts/imports.txt +++ b/testdata/scripts/imports.txt @@ -2,7 +2,7 @@ garble build exec ./main cmp stdout main.stdout -! bingrep main$exe 'ImportedVar' 'ImportedConst' 'ImportedFunc' 'ImportedType' +! binsubstr main$exe 'ImportedVar' 'ImportedConst' 'ImportedFunc' 'ImportedType' [short] stop # checking that the build is reproducible is slow diff --git a/testdata/scripts/modinfo.txt b/testdata/scripts/modinfo.txt index eab1305..84071fd 100644 --- a/testdata/scripts/modinfo.txt +++ b/testdata/scripts/modinfo.txt @@ -1,12 +1,12 @@ exec go build exec ./main cmp stdout main.stdout-orig -bingrep main$exe '\(devel\)' +binsubstr main$exe '(devel)' garble build exec ./main cmp stdout main.stdout -! bingrep main$exe '\(devel\)' +! binsubstr main$exe '(devel)' -- go.mod -- module foo.com/main diff --git a/testdata/scripts/test.txt b/testdata/scripts/test.txt index 398cd89..e47f459 100644 --- a/testdata/scripts/test.txt +++ b/testdata/scripts/test.txt @@ -2,8 +2,8 @@ exec go test -v stdout 'PASS.*TestFoo' garble test -c -bingrep bar.test$exe 'TestFoo' 'TestSeparateFoo' -! bingrep bar.test$exe 'ImportedVar' +binsubstr bar.test$exe 'TestFoo' 'TestSeparateFoo' +! binsubstr bar.test$exe 'ImportedVar' exec ./bar.test -test.v stdout 'PASS.*TestFoo'