set testscript's RequireExplicitExec and RequireUniqueNames

The first makes our test scripts more consistent, as all external
program executions happen via "exec" and are not as easily confused
with custom builtin commands like our "generate-literals".

The second catches mistakes if any of our txtar files have duplicate
files, where all but one of the contents would be ignored before.
pull/728/head
Daniel Martí 2 years ago
parent 7bb040e635
commit e6fc593f68

@ -133,7 +133,9 @@ func TestScript(t *testing.T) {
"setenvfile": setenvfile, "setenvfile": setenvfile,
"grepfiles": grepfiles, "grepfiles": grepfiles,
}, },
UpdateScripts: *update, UpdateScripts: *update,
RequireExplicitExec: true,
RequireUniqueNames: true,
} }
if err := gotooltest.Setup(&p); err != nil { if err := gotooltest.Setup(&p); err != nil {
t.Fatal(err) t.Fatal(err)

@ -3,13 +3,13 @@
# TODO: support arm64, at least # TODO: support arm64, at least
[!amd64] skip 'the assembly is only written for amd64' [!amd64] skip 'the assembly is only written for amd64'
garble build exec garble build
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr
! binsubstr main$exe 'test/main' 'addJmp' 'AddImpl' 'garble_' ! binsubstr main$exe 'test/main' 'addJmp' 'AddImpl' 'garble_'
# We used to panic on broken packages with assembly. # We used to panic on broken packages with assembly.
! garble build ./broken/... ! exec garble build ./broken/...
stderr -count=1 'broken[/\\]asm[/\\].*MissingType' stderr -count=1 'broken[/\\]asm[/\\].*MissingType'
stderr -count=1 'broken[/\\]syntax[/\\].*unexpected newline' stderr -count=1 'broken[/\\]syntax[/\\].*unexpected newline'
@ -18,10 +18,10 @@ stderr -count=1 'broken[/\\]syntax[/\\].*unexpected newline'
# Ensure that reversing doesn't error with assembly files. # Ensure that reversing doesn't error with assembly files.
# It should fail, as there is nothing to reverse, but without any parse error. # It should fail, as there is nothing to reverse, but without any parse error.
stdin empty-reverse.txt stdin empty-reverse.txt
! garble reverse . ! exec garble reverse .
! stderr . ! stderr .
garble -tiny build exec garble -tiny build
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr
! binsubstr main$exe 'addJmp' 'AddImpl' ! binsubstr main$exe 'addJmp' 'AddImpl'

@ -6,7 +6,7 @@
[amd64] [!darwin] env GOARCH=386 [amd64] [!darwin] env GOARCH=386
[arm64] [!darwin] env GOARCH=arm [arm64] [!darwin] env GOARCH=arm
garble build exec garble build
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr

@ -1,5 +1,5 @@
# Check that the simplest use of garble works. Note the lack of a module or GOGARBLE. # Check that the simplest use of garble works. Note the lack of a module or GOGARBLE.
garble build -o=main$exe garble_main.go exec garble build -o=main$exe garble_main.go
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr
@ -37,7 +37,7 @@ stderr 'cannot open shared file.*did you run.*instead of "garble \[command\]"'
# No packages should be rebuilt either, thanks to the build cache. # No packages should be rebuilt either, thanks to the build cache.
cp main$exe main_old$exe cp main$exe main_old$exe
rm main$exe rm main$exe
garble build -v -o=main$exe garble_main.go exec garble build -v -o=main$exe garble_main.go
! stderr . ! stderr .
bincmp main$exe main_old$exe bincmp main$exe main_old$exe

@ -1,6 +1,6 @@
[!cgo] skip 'this test requires cgo to be enabled' [!cgo] skip 'this test requires cgo to be enabled'
garble build exec garble build
! stderr 'warning' # check that the C toolchain is happy ! stderr 'warning' # check that the C toolchain is happy
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout
@ -13,11 +13,11 @@ env GARBLE_TEST_REVERSING=true
exec ./main exec ./main
cp stdout reversing.stdout cp stdout reversing.stdout
stdin reversing.stdout stdin reversing.stdout
garble reverse . exec garble reverse .
cmp stdout reversed.stdout cmp stdout reversed.stdout
env GARBLE_TEST_REVERSING=false env GARBLE_TEST_REVERSING=false
garble -tiny build exec garble -tiny build
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout

@ -16,7 +16,7 @@
[windows] env GOOS=linux [windows] env GOOS=linux
[!arm] env GOARCH=arm [!arm] env GOARCH=arm
[arm] env GOARCH=arm64 [arm] env GOARCH=arm64
garble build -gcflags=math/bits=-d=ssa/intrinsics/debug=1 exec garble build -gcflags=math/bits=-d=ssa/intrinsics/debug=1
stderr 'intrinsic substitution for Len64.*BitLen64' stderr 'intrinsic substitution for Len64.*BitLen64'
-- go.mod -- -- go.mod --
module test/main module test/main

@ -1,4 +1,4 @@
garble -debugdir ./debug1 build exec garble -debugdir ./debug1 build
exists 'debug1/test/main/imported/imported.go' 'debug1/test/main/main.go' 'debug1/reflect/type.go' exists 'debug1/test/main/imported/imported.go' 'debug1/test/main/main.go' 'debug1/reflect/type.go'
exists 'debug1/runtime/map.go' 'debug1/runtime/funcdata.h' 'debug1/runtime/asm.s' exists 'debug1/runtime/map.go' 'debug1/runtime/funcdata.h' 'debug1/runtime/asm.s'
[amd64] exists 'debug1/runtime/cpuflags_amd64.go' 'debug1/runtime/asm_amd64.s' [amd64] exists 'debug1/runtime/cpuflags_amd64.go' 'debug1/runtime/asm_amd64.s'
@ -12,7 +12,7 @@ exists 'debug1/runtime/map.go' 'debug1/runtime/funcdata.h' 'debug1/runtime/asm.s
# Sources from previous builds should be deleted # Sources from previous builds should be deleted
cp $WORK/debug1/test/main/main.go $WORK/debug1/some_file_from_prev_build.go cp $WORK/debug1/test/main/main.go $WORK/debug1/some_file_from_prev_build.go
garble -debugdir ./debug1 build -v exec garble -debugdir ./debug1 build -v
stderr 'test/main' # we force rebuilds with -debugdir stderr 'test/main' # we force rebuilds with -debugdir
! exists $WORK/debug1/some_file_from_prev_build.go ! exists $WORK/debug1/some_file_from_prev_build.go
-- go.mod -- -- go.mod --

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout

@ -1,11 +1,11 @@
# Ensure that "does not match any packages" works. # Ensure that "does not match any packages" works.
env GOGARBLE=match-absolutely/nothing env GOGARBLE=match-absolutely/nothing
! garble build -o=out ./standalone ! exec garble build -o=out ./standalone
stderr '^GOGARBLE="match-absolutely/nothing" does not match any packages to be built$' stderr '^GOGARBLE="match-absolutely/nothing" does not match any packages to be built$'
# A build where just some packages are obfuscated. # A build where just some packages are obfuscated.
env GOGARBLE=test/main/imported env GOGARBLE=test/main/imported
garble -literals build -o=out ./importer exec garble -literals build -o=out ./importer
! binsubstr out 'some long string to obfuscate' ! binsubstr out 'some long string to obfuscate'
binsubstr out 'some long string to not obfuscate' binsubstr out 'some long string to not obfuscate'
@ -14,7 +14,7 @@ binsubstr out 'some long string to not obfuscate'
# Some of the imported std packages use "import maps" due to vendoring, # Some of the imported std packages use "import maps" due to vendoring,
# and a past bug made this case fail for "garble build". # and a past bug made this case fail for "garble build".
env GOGARBLE=test/main env GOGARBLE=test/main
garble build -o=out ./stdimporter exec garble build -o=out ./stdimporter
[short] stop # rebuilding std is slow [short] stop # rebuilding std is slow
@ -28,12 +28,12 @@ env GOGARBLE='*'
# packages so we must properly support ImportMap. # packages so we must properly support ImportMap.
# Plus, some packages like net make heavy use of complex features like Cgo. # Plus, some packages like net make heavy use of complex features like Cgo.
# Note that we won't obfuscate a few std packages just yet, mainly those around runtime. # Note that we won't obfuscate a few std packages just yet, mainly those around runtime.
garble build std exec garble build std
# Link a binary importing net/http, which will catch whether or not we # Link a binary importing net/http, which will catch whether or not we
# support ImportMap when linking. # support ImportMap when linking.
# Also ensure we are obfuscating low-level std packages. # Also ensure we are obfuscating low-level std packages.
garble build -o=out ./stdimporter exec garble build -o=out ./stdimporter
! binsubstr out 'http.ListenAndServe' 'debug.WriteHeapDump' 'time.Now' 'syscall.Listen' ! binsubstr out 'http.ListenAndServe' 'debug.WriteHeapDump' 'time.Now' 'syscall.Listen'
# The same low-level std packages appear in plain sight in regular builds. # The same low-level std packages appear in plain sight in regular builds.
@ -45,8 +45,8 @@ binsubstr out_regular 'http.ListenAndServe' 'debug.WriteHeapDump' 'time.Now' 'sy
# We also forcibly rebuild runtime on its own, given it used to be non-reproducible # We also forcibly rebuild runtime on its own, given it used to be non-reproducible
# due to its use of linknames pointing at std packages it doesn't depend upon. # due to its use of linknames pointing at std packages it doesn't depend upon.
env GOCACHE=${WORK}/gocache-empty env GOCACHE=${WORK}/gocache-empty
garble build -a runtime exec garble build -a runtime
garble build -o=out_rebuild ./stdimporter exec garble build -o=out_rebuild ./stdimporter
bincmp out_rebuild out bincmp out_rebuild out
-- go.mod -- -- go.mod --
module test/main module test/main

@ -6,74 +6,74 @@ env PATH=${WORK}/.bin${:}${PATH}
# An empty go version. # An empty go version.
env TOOLCHAIN_GOVERSION='' env TOOLCHAIN_GOVERSION=''
! garble build ! exec garble build
stderr 'Go version is too old; please upgrade to Go 1\.20\.x or newer' stderr 'Go version is too old; please upgrade to Go 1\.20\.x or newer'
# We should error on a devel version that's too old. # We should error on a devel version that's too old.
# Note that they lacked the "goN.M-" prefix. # Note that they lacked the "goN.M-" prefix.
env TOOLCHAIN_GOVERSION='devel +afb5fca Sun Aug 07 00:00:00 2020 +0000' env TOOLCHAIN_GOVERSION='devel +afb5fca Sun Aug 07 00:00:00 2020 +0000'
! garble build ! exec garble build
stderr 'Go version is too old; please upgrade to Go 1\.20\.x or newer' stderr 'Go version is too old; please upgrade to Go 1\.20\.x or newer'
# Another form of old version; with an old "goN.M-" prefix. # Another form of old version; with an old "goN.M-" prefix.
env TOOLCHAIN_GOVERSION='devel go1.15-afb5fca Sun Aug 07 00:00:00 2020 +0000' env TOOLCHAIN_GOVERSION='devel go1.15-afb5fca Sun Aug 07 00:00:00 2020 +0000'
! garble build ! exec garble build
stderr 'Go version "devel go1\.15-.*2020.*" is too old; please upgrade to Go 1\.20\.x' stderr 'Go version "devel go1\.15-.*2020.*" is too old; please upgrade to Go 1\.20\.x'
# A current devel version should be fine. # A current devel version should be fine.
# Note that we don't look at devel version timestamps. # Note that we don't look at devel version timestamps.
env GARBLE_TEST_GOVERSION='go1.20' env GARBLE_TEST_GOVERSION='go1.20'
env TOOLCHAIN_GOVERSION='devel go1.20-ad97d204f0 Sun Sep 12 16:46:58 2023 +0000' env TOOLCHAIN_GOVERSION='devel go1.20-ad97d204f0 Sun Sep 12 16:46:58 2023 +0000'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
# We should error on a stable version that's too old. # We should error on a stable version that's too old.
env TOOLCHAIN_GOVERSION='go1.14' env TOOLCHAIN_GOVERSION='go1.14'
! garble build ! exec garble build
stderr 'Go version "go1\.14" is too old; please upgrade to Go 1\.20\.x or newer' stderr 'Go version "go1\.14" is too old; please upgrade to Go 1\.20\.x or newer'
# We should accept a future stable version. # We should accept a future stable version.
# Note that we need to bump the version of Go that supposedly built it, too. # Note that we need to bump the version of Go that supposedly built it, too.
env GARBLE_TEST_GOVERSION='go1.28.2' env GARBLE_TEST_GOVERSION='go1.28.2'
env TOOLCHAIN_GOVERSION='go1.28.2' env TOOLCHAIN_GOVERSION='go1.28.2'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
# We should accept custom devel strings. # We should accept custom devel strings.
env TOOLCHAIN_GOVERSION='devel go1.20-somecustomversion' env TOOLCHAIN_GOVERSION='devel go1.20-somecustomversion'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
# The current toolchain may be older than the one that built garble. # The current toolchain may be older than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.21' env GARBLE_TEST_GOVERSION='go1.21'
env TOOLCHAIN_GOVERSION='go1.20.3' env TOOLCHAIN_GOVERSION='go1.20.3'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
# The current toolchain may be equal to the one that built garble. # The current toolchain may be equal to the one that built garble.
env GARBLE_TEST_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000' env GARBLE_TEST_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
env TOOLCHAIN_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000' env TOOLCHAIN_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
# The current toolchain must not be newer than the one that built garble. # The current toolchain must not be newer than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.18' env GARBLE_TEST_GOVERSION='go1.18'
env TOOLCHAIN_GOVERSION='go1.20.1' env TOOLCHAIN_GOVERSION='go1.20.1'
! garble build ! exec garble build
stderr 'garble was built with "go1\.18" and is being used with "go1\.20\.1"; please rebuild garble with the newer version' stderr 'garble was built with "go1\.18" and is being used with "go1\.20\.1"; please rebuild garble with the newer version'
# We'll error even if the difference is a minor (bugfix) level. # We'll error even if the difference is a minor (bugfix) level.
# In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs. # In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs.
env GARBLE_TEST_GOVERSION='go1.20.11' env GARBLE_TEST_GOVERSION='go1.20.11'
env TOOLCHAIN_GOVERSION='go1.20.14' env TOOLCHAIN_GOVERSION='go1.20.14'
! garble build ! exec garble build
stderr 'garble was built with "go1\.20\.11" and is being used with "go1\.20\.14"; please rebuild garble with the newer version' stderr 'garble was built with "go1\.20\.11" and is being used with "go1\.20\.14"; please rebuild garble with the newer version'
# If garble builds itself and is then used, it won't know what version built it. # If garble builds itself and is then used, it won't know what version built it.
# As a fallback, we drop the comparison against the toolchain's version. # As a fallback, we drop the comparison against the toolchain's version.
env GARBLE_TEST_GOVERSION='bogus version' env GARBLE_TEST_GOVERSION='bogus version'
env TOOLCHAIN_GOVERSION='go1.20.3' env TOOLCHAIN_GOVERSION='go1.20.3'
! garble build ! exec garble build
stderr 'mocking the real build' stderr 'mocking the real build'
-- go.mod -- -- go.mod --
module test/main module test/main

@ -1,29 +1,29 @@
! garble ! exec garble
stderr 'Garble obfuscates Go code' stderr 'Garble obfuscates Go code'
stderr 'garble \[garble flags\] command' stderr 'garble \[garble flags\] command'
! stderr 'usage: go build' ! stderr 'usage: go build'
! stdout . ! stdout .
! garble -h ! exec garble -h
stderr 'Garble obfuscates Go code' stderr 'Garble obfuscates Go code'
stderr 'garble \[garble flags\] command' stderr 'garble \[garble flags\] command'
! stdout . ! stdout .
! garble help ! exec garble help
stderr 'Garble obfuscates Go code' stderr 'Garble obfuscates Go code'
stderr 'garble \[garble flags\] command' stderr 'garble \[garble flags\] command'
! stdout . ! stdout .
! garble help foo bar ! exec garble help foo bar
stderr 'usage: garble help' stderr 'usage: garble help'
! stderr 'Garble obfuscates Go code' ! stderr 'Garble obfuscates Go code'
! stdout . ! stdout .
! garble help -h ! exec garble help -h
stderr 'usage: garble help' stderr 'usage: garble help'
! stdout . ! stdout .
! garble build -h ! exec garble build -h
stderr 'garble \[garble flags\] build' stderr 'garble \[garble flags\] build'
stderr 'This command wraps "go build"' stderr 'This command wraps "go build"'
stderr 'usage: go build' stderr 'usage: go build'
@ -31,7 +31,7 @@ stderr 'Run .go help build.'
! stderr 'Garble obfuscates Go code' ! stderr 'Garble obfuscates Go code'
! stdout . ! stdout .
! garble test -h ! exec garble test -h
stderr 'garble \[garble flags\] test' stderr 'garble \[garble flags\] test'
stderr 'This command wraps "go test"' stderr 'This command wraps "go test"'
stderr 'usage: go test' stderr 'usage: go test'
@ -39,49 +39,49 @@ stderr 'Run .go help test.'
! stderr 'Garble obfuscates Go code' ! stderr 'Garble obfuscates Go code'
! stdout . ! stdout .
! garble reverse -h ! exec garble reverse -h
stderr 'garble \[garble flags\] reverse \[build flags\] package \[files\]' stderr 'garble \[garble flags\] reverse \[build flags\] package \[files\]'
! stderr 'usage: go ' ! stderr 'usage: go '
! stdout . ! stdout .
! garble help reverse ! exec garble help reverse
stderr 'garble \[garble flags\] reverse \[build flags\] package \[files\]' stderr 'garble \[garble flags\] reverse \[build flags\] package \[files\]'
! stderr 'usage: go ' ! stderr 'usage: go '
! stdout . ! stdout .
! garble -badflag ! exec garble -badflag
stderr 'flag provided but not defined' stderr 'flag provided but not defined'
stderr 'garble \[garble flags\] command' stderr 'garble \[garble flags\] command'
! stdout . ! stdout .
! garble badcmd ! exec garble badcmd
stderr 'unknown command' stderr 'unknown command'
! garble build -badflag ! exec garble build -badflag
stderr 'usage: go build' # TODO: is this confusing? stderr 'usage: go build' # TODO: is this confusing?
! stdout . ! stdout .
! garble build -tiny ! exec garble build -tiny
stderr 'must precede command, like: garble -tiny build \./pkg' stderr 'must precede command, like: garble -tiny build \./pkg'
! stdout . ! stdout .
! garble build -literals ! exec garble build -literals
stderr 'must precede command, like: garble -literals build \./pkg' stderr 'must precede command, like: garble -literals build \./pkg'
! stdout . ! stdout .
! garble build -seed=random ! exec garble build -seed=random
stderr 'must precede command, like: garble -seed=random build \./pkg' stderr 'must precede command, like: garble -seed=random build \./pkg'
! stdout . ! stdout .
[!windows] ! garble toolexec /does/not/exist/compile [!windows] ! exec garble toolexec /does/not/exist/compile
[windows] ! garble toolexec C:\does\not\exist\compile [windows] ! exec garble toolexec C:\does\not\exist\compile
stderr 'did you run.*instead of "garble \[command\]"' stderr 'did you run.*instead of "garble \[command\]"'
! garble build badpackage ! exec garble build badpackage
stderr 'package badpackage is not in GOROOT' stderr 'package badpackage is not in GOROOT'
! stdout . ! stdout .
! garble build ./badpackage ! exec garble build ./badpackage
stderr 'directory not found' stderr 'directory not found'
! stdout . ! stdout .
@ -90,7 +90,7 @@ stderr 'directory not found'
# To avoid building another garble binary, # To avoid building another garble binary,
# and to be able to use static VCS info, use an environment variable. # and to be able to use static VCS info, use an environment variable.
# First, test without the information, and then with it. # First, test without the information, and then with it.
garble version exec garble version
stdout -count=1 'mvdan.cc/garble \(devel\)' stdout -count=1 'mvdan.cc/garble \(devel\)'
stdout -count=1 'Build settings' stdout -count=1 'Build settings'
stdout -count=3 '-compiler|GOOS|GOARCH' stdout -count=3 '-compiler|GOOS|GOARCH'
@ -98,7 +98,7 @@ stdout -count=3 '-compiler|GOOS|GOARCH'
# Obtained from a real build while developing. # Obtained from a real build while developing.
env GARBLE_TEST_BUILDSETTINGS='[{"Key":"vcs","Value":"git"},{"Key":"vcs.revision","Value":"91ea246349544769f5100c29f79cb0f173abfeea"},{"Key":"vcs.time","Value":"2022-03-18T13:45:11Z"},{"Key":"vcs.modified","Value":"true"}]' env GARBLE_TEST_BUILDSETTINGS='[{"Key":"vcs","Value":"git"},{"Key":"vcs.revision","Value":"91ea246349544769f5100c29f79cb0f173abfeea"},{"Key":"vcs.time","Value":"2022-03-18T13:45:11Z"},{"Key":"vcs.modified","Value":"true"}]'
garble version exec garble version
stdout -count=1 'mvdan\.cc/garble v0\.0\.0-20220318134511-91ea24634954' stdout -count=1 'mvdan\.cc/garble v0\.0\.0-20220318134511-91ea24634954'
stdout -count=1 'Build settings' stdout -count=1 'Build settings'
stdout -count=3 '-compiler|GOOS|GOARCH' stdout -count=3 '-compiler|GOOS|GOARCH'
@ -107,10 +107,10 @@ stdout -count=1 'vcs\.revision 91ea246349544769f5100c29f79cb0f173abfeea'
stdout -count=1 'vcs\.time 2022-03-18T13:45:11Z' stdout -count=1 'vcs\.time 2022-03-18T13:45:11Z'
stdout -count=1 'vcs\.modified true' stdout -count=1 'vcs\.modified true'
! garble version -flag ! exec garble version -flag
stderr 'usage: garble version' stderr 'usage: garble version'
! garble version arg ! exec garble version arg
stderr 'usage: garble version' stderr 'usage: garble version'
# We need a dummy module for "garble build -badflag". # We need a dummy module for "garble build -badflag".

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout

@ -14,7 +14,7 @@
# go clean -modcache && go get -d rsc.io/quote@v1.5.2 && go test -short # go clean -modcache && go get -d rsc.io/quote@v1.5.2 && go test -short
env GOMODCACHE=$WORK/modcache env GOMODCACHE=$WORK/modcache
garble build -tags buildtag exec garble build -tags buildtag
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout
@ -26,7 +26,7 @@ cmp stdout main.stdout
# No packages should be rebuilt either, thanks to the build cache. # No packages should be rebuilt either, thanks to the build cache.
cp main$exe main_old$exe cp main$exe main_old$exe
rm main$exe rm main$exe
garble build -tags buildtag -v exec garble build -tags buildtag -v
! stderr . ! stderr .
bincmp main$exe main_old$exe bincmp main$exe main_old$exe
@ -36,7 +36,7 @@ cmp stdout main.stdout
# Check that -literals doesn't break anything. # Check that -literals doesn't break anything.
# Also check that a different form of -tags still works. # Also check that a different form of -tags still works.
garble -literals build --tags=buildtag exec garble -literals build --tags=buildtag
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout
-- go.mod -- -- go.mod --

@ -1,6 +1,6 @@
# Test that garble keeps init functions in the order they were declared in. # Test that garble keeps init functions in the order they were declared in.
garble build exec garble build
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr

@ -7,14 +7,14 @@
# -X "name=value" (or with single quotes, allows spaces in value) # -X "name=value" (or with single quotes, allows spaces in value)
env LDFLAGS='-X=main.unexportedVersion=v1.22.33 -X=main.replacedWithEmpty= -X "main.replacedWithSpaces= foo bar " -X=domain.test/main/imported.ExportedUnset=garble_replaced -X=domain.test/missing/path.missingVar=value -X=main.someType=notAVariable' env LDFLAGS='-X=main.unexportedVersion=v1.22.33 -X=main.replacedWithEmpty= -X "main.replacedWithSpaces= foo bar " -X=domain.test/main/imported.ExportedUnset=garble_replaced -X=domain.test/missing/path.missingVar=value -X=main.someType=notAVariable'
garble build -ldflags=${LDFLAGS} exec garble build -ldflags=${LDFLAGS}
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout
! binsubstr main$exe 'domain.test/main' 'unexportedVersion' 'ExportedUnset' ! binsubstr main$exe 'domain.test/main' 'unexportedVersion' 'ExportedUnset'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
garble -tiny -literals -seed=0002deadbeef build -ldflags=${LDFLAGS} exec garble -tiny -literals -seed=0002deadbeef build -ldflags=${LDFLAGS}
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout
! binsubstr main$exe 'unexportedVersion' 'ExportedUnset' ! binsubstr main$exe 'unexportedVersion' 'ExportedUnset'

@ -8,7 +8,7 @@
# those commands are likely to fail as std and cmd are their own modules. # those commands are likely to fail as std and cmd are their own modules.
env GOFLAGS=-modfile=${WORK}/go.mod env GOFLAGS=-modfile=${WORK}/go.mod
garble build exec garble build
exec ./main exec ./main
! cmp stderr main.stderr ! cmp stderr main.stderr
@ -19,7 +19,7 @@ exec ./main
# building the linker twice, wasting CPU and disk. # building the linker twice, wasting CPU and disk.
[!windows] env GOOS=windows [!windows] env GOOS=windows
[windows] env GOOS=linux [windows] env GOOS=linux
garble build exec garble build
[!windows] [exec:git] exists ${GARBLE_CACHE_DIR}/garble/link [!windows] [exec:git] exists ${GARBLE_CACHE_DIR}/garble/link
[!windows] [exec:git] ! exists ${GARBLE_CACHE_DIR}/garble/link.exe [!windows] [exec:git] ! exists ${GARBLE_CACHE_DIR}/garble/link.exe
[windows] [exec:git] ! exists ${GARBLE_CACHE_DIR}/garble/link [windows] [exec:git] ! exists ${GARBLE_CACHE_DIR}/garble/link

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main exec ./main
cmp stderr main.stderr cmp stderr main.stderr

@ -1,4 +1,4 @@
! garble build ./... ! exec garble build ./...
cmpenv stderr stderr.golden cmpenv stderr stderr.golden
-- stderr.golden -- -- stderr.golden --

@ -1,4 +1,4 @@
garble -literals build exec garble -literals build
exec ./main$exe exec ./main$exe
cmp stderr main.stderr cmp stderr main.stderr
@ -10,7 +10,7 @@ binsubstr main$exe 'skip typed const' 'skip typed var' 'skip typed var assign' '
# Also check that the binary is reproducible. # Also check that the binary is reproducible.
cp main$exe main_old$exe cp main$exe main_old$exe
rm main$exe rm main$exe
garble -literals build exec garble -literals build
bincmp main$exe main_old$exe bincmp main$exe main_old$exe
# Check that the program works as expected without garble. # Check that the program works as expected without garble.
@ -30,7 +30,7 @@ go build
binsubstr main$exe 'a_unique_string_that_is_part_of_all_extra_literals' binsubstr main$exe 'a_unique_string_that_is_part_of_all_extra_literals'
# ensure we don't find the extra literals in an obfuscated build # ensure we don't find the extra literals in an obfuscated build
garble -literals -debugdir=debug1 build exec garble -literals -debugdir=debug1 build
exec ./main$exe exec ./main$exe
cmp stderr main.stderr cmp stderr main.stderr
! binsubstr main$exe 'a_unique_string_that_is_part_of_all_extra_literals' ! binsubstr main$exe 'a_unique_string_that_is_part_of_all_extra_literals'
@ -55,7 +55,7 @@ grep '^\s+type \w+ func\(byte\) \w+$' debug1/test/main/extra_literals.go
# Finally, sanity check that we can build all of std with -literals. # Finally, sanity check that we can build all of std with -literals.
# Analogous to gogarble.txt. # Analogous to gogarble.txt.
garble -literals build std exec garble -literals build std
-- go.mod -- -- go.mod --
module test/main module test/main

@ -6,7 +6,7 @@
[exec:git] exec git rev-parse HEAD [exec:git] exec git rev-parse HEAD
[exec:git] setenvfile HEAD_COMMIT_SHA stdout [exec:git] setenvfile HEAD_COMMIT_SHA stdout
garble build -tags veryuniquebuildtag exec garble build -tags veryuniquebuildtag
! binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA} ! binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
go version -m main$exe go version -m main$exe

@ -2,7 +2,7 @@ skip # TODO: get plugins working properly. See issue #87
[windows] skip 'Go plugins are not supported on Windows' [windows] skip 'Go plugins are not supported on Windows'
garble build -buildmode=plugin ./plugin exec garble build -buildmode=plugin ./plugin
binsubstr plugin.so 'PublicVar' 'PublicFunc' binsubstr plugin.so 'PublicVar' 'PublicFunc'
! binsubstr plugin.so 'privateFunc' ! binsubstr plugin.so 'privateFunc'
@ -16,7 +16,7 @@ binsubstr main$exe 'PublicVar' 'PublicFunc'
# This used to fail, since in this case the package path for the ad-hoc plugin # This used to fail, since in this case the package path for the ad-hoc plugin
# package isn't "main", but "plugin/unnamed-*". # package isn't "main", but "plugin/unnamed-*".
garble build -buildmode=plugin plugin/main.go exec garble build -buildmode=plugin plugin/main.go
go build -buildmode=plugin ./plugin go build -buildmode=plugin ./plugin
binsubstr plugin.so 'PublicVar' 'PublicFunc' 'privateFunc' binsubstr plugin.so 'PublicVar' 'PublicFunc' 'privateFunc'

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main exec ./main
! stdout 'garble_main\.go|garble_other_filename|is sorted' ! stdout 'garble_main\.go|garble_other_filename|is sorted'

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stdout main.stdout

@ -1,8 +1,8 @@
# Unknown build flags should result in errors. # Unknown build flags should result in errors.
! garble reverse -badflag=foo . ! exec garble reverse -badflag=foo .
stderr 'flag provided but not defined' stderr 'flag provided but not defined'
garble build exec garble build
exec ./main exec ./main
cp stderr main.stderr cp stderr main.stderr
@ -16,18 +16,18 @@ grep 'goroutine 1 \[running\]' main.stderr
! grep 'ExportedLib(Type|Field)|unexportedMainFunc|test/main|long_main\.go|long_lib\.go' main.stderr ! grep 'ExportedLib(Type|Field)|unexportedMainFunc|test/main|long_main\.go|long_lib\.go' main.stderr
stdin main.stderr stdin main.stderr
garble reverse . exec garble reverse .
cmp stdout reverse.stdout cmp stdout reverse.stdout
# Ensure that we cleaned up the temporary files. # Ensure that we cleaned up the temporary files.
# Note that we rely on the unix-like TMPDIR env var name. # Note that we rely on the unix-like TMPDIR env var name.
[!windows] ! grepfiles ${TMPDIR} 'garble|importcfg|cache\.gob|\.go' [!windows] ! grepfiles ${TMPDIR} 'garble|importcfg|cache\.gob|\.go'
! garble build ./build-error ! exec garble build ./build-error
cp stderr build-error.stderr cp stderr build-error.stderr
stdin build-error.stderr stdin build-error.stderr
garble reverse ./build-error exec garble reverse ./build-error
cmp stdout build-error-reverse.stdout cmp stdout build-error-reverse.stdout
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
@ -38,17 +38,17 @@ exec ./main
cmp stderr reverse.stdout cmp stderr reverse.stdout
# Ensure that we can still reverse with -literals. # Ensure that we can still reverse with -literals.
garble -literals build exec garble -literals build
exec ./main exec ./main
cp stderr main-literals.stderr cp stderr main-literals.stderr
stdin main-literals.stderr stdin main-literals.stderr
garble -literals reverse . exec garble -literals reverse .
cmp stdout reverse.stdout cmp stdout reverse.stdout
# Reversing a -literals output without the flag should fail. # Reversing a -literals output without the flag should fail.
stdin main-literals.stderr stdin main-literals.stderr
! garble reverse . ! exec garble reverse .
cmp stdout main-literals.stderr cmp stdout main-literals.stderr
-- go.mod -- -- go.mod --
module test/main module test/main

@ -1,11 +1,11 @@
garble run garble_main.go exec garble run garble_main.go
! stdout '^garble_main\.go 9$' ! stdout '^garble_main\.go 9$'
stdout '\.go \d' stdout '\.go \d'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
# also with a package # also with a package
garble run . exec garble run .
! stdout '^garble_main\.go 9$' ! stdout '^garble_main\.go 9$'
stdout '\.go \d' stdout '\.go \d'

@ -10,7 +10,7 @@ env SEED1=OQg9kACEECQ
# First, ensure that mod1's garbletest.v2 is in the cache. # First, ensure that mod1's garbletest.v2 is in the cache.
cd mod1 cd mod1
garble -seed=${SEED1} build gopkg.in/garbletest.v2 exec garble -seed=${SEED1} build gopkg.in/garbletest.v2
# We collect the Action IDs to ensure they're different. # We collect the Action IDs to ensure they're different.
# This is one of the factors that confused garble. # This is one of the factors that confused garble.
@ -20,7 +20,7 @@ cp stdout ../buildid-mod1
# Then, do the mod2 build, using the different-but-equal garbletest.v2. # Then, do the mod2 build, using the different-but-equal garbletest.v2.
# Ensure that our workaround's inserted garbleActionID does not end up in the binary. # Ensure that our workaround's inserted garbleActionID does not end up in the binary.
cd ../mod2 cd ../mod2
garble -seed=${SEED1} build exec garble -seed=${SEED1} build
! binsubstr mod2$exe 'garbleActionID' ! binsubstr mod2$exe 'garbleActionID'
go list -trimpath -export -f '{{.BuildID}}' gopkg.in/garbletest.v2 go list -trimpath -export -f '{{.BuildID}}' gopkg.in/garbletest.v2

@ -9,7 +9,7 @@ env SEED1=OQg9kACEECQ
env SEED2=NruiDmVz6/s env SEED2=NruiDmVz6/s
# Check the binary with a given base64 encoded seed. # Check the binary with a given base64 encoded seed.
garble -seed=${SEED1} build exec garble -seed=${SEED1} build
exec ./main$exe exec ./main$exe
cmp stderr main.stderr cmp stderr main.stderr
binsubstr main$exe 'teststring' 'imported var value' binsubstr main$exe 'teststring' 'imported var value'
@ -24,7 +24,7 @@ cp stderr importedpkg-seed-static-1
# No packages should be rebuilt either, thanks to the build cache. # No packages should be rebuilt either, thanks to the build cache.
cp main$exe main_seed1$exe cp main$exe main_seed1$exe
rm main$exe rm main$exe
garble -seed=${SEED1}= build -v exec garble -seed=${SEED1}= build -v
! stderr . ! stderr .
bincmp main$exe main_seed1$exe bincmp main$exe main_seed1$exe
@ -42,11 +42,11 @@ cp stderr mainpkg-seed-static-1
# TODO: also test that changing non-garble build parameters, # TODO: also test that changing non-garble build parameters,
# such as GOARCH or -tags, still results in the same hashing via the seed. # such as GOARCH or -tags, still results in the same hashing via the seed.
garble -seed=${SEED1} -literals build exec garble -seed=${SEED1} -literals build
exec ./main$exe test/main/imported exec ./main$exe test/main/imported
cmp stderr importedpkg-seed-static-1 cmp stderr importedpkg-seed-static-1
garble -seed=${SEED1} -tiny build exec garble -seed=${SEED1} -tiny build
exec ./main$exe test/main/imported exec ./main$exe test/main/imported
cmp stderr importedpkg-seed-static-1 cmp stderr importedpkg-seed-static-1
@ -54,7 +54,7 @@ cmp stderr importedpkg-seed-static-1
# We can't know if caching happens here, because of previous test runs. # We can't know if caching happens here, because of previous test runs.
cp main$exe main_seed2$exe cp main$exe main_seed2$exe
rm main$exe rm main$exe
garble -seed=${SEED2} build exec garble -seed=${SEED2} build
! bincmp main$exe main_seed2$exe ! bincmp main$exe main_seed2$exe
exec ./main$exe test/main/imported exec ./main$exe test/main/imported
@ -62,7 +62,7 @@ cp stderr importedpkg-seed-static-2
! bincmp importedpkg-seed-static-2 importedpkg-seed-static-1 ! bincmp importedpkg-seed-static-2 importedpkg-seed-static-1
# Use a random seed, which should always trigger a full build. # Use a random seed, which should always trigger a full build.
garble -seed=random build -v exec garble -seed=random build -v
stderr -count=1 '^-seed chosen at random: .+' stderr -count=1 '^-seed chosen at random: .+'
stderr -count=1 '^runtime$' stderr -count=1 '^runtime$'
stderr -count=1 '^test/main$' stderr -count=1 '^test/main$'
@ -78,7 +78,7 @@ cp stderr importedpkg-seed-random-1
# Also check that the random binary is not reproducible. # Also check that the random binary is not reproducible.
cp main$exe main_random$exe cp main$exe main_random$exe
rm main$exe rm main$exe
garble -seed=random build -v exec garble -seed=random build -v
stderr . stderr .
! bincmp main$exe main_random$exe ! bincmp main$exe main_random$exe

@ -1,4 +1,4 @@
garble build exec garble build
exec ./main$exe exec ./main$exe
cmp stderr main.stderr cmp stderr main.stderr

@ -1,5 +1,5 @@
# build the test binary # build the test binary
garble test -c exec garble test -c
! stdout 'PASS' ! stdout 'PASS'
binsubstr bar.test$exe 'TestFoo' 'TestSeparateFoo' binsubstr bar.test$exe 'TestFoo' 'TestSeparateFoo'
! binsubstr bar.test$exe 'LocalFoo|ImportedVar|OriginalFuncName' ! binsubstr bar.test$exe 'LocalFoo|ImportedVar|OriginalFuncName'
@ -25,7 +25,7 @@ stdout 'package bar_test, func name:'
# #
# The combination of those used to result in "refusing to list non-dependency # The combination of those used to result in "refusing to list non-dependency
# package" errors, which we've currently worked around. # package" errors, which we've currently worked around.
garble test -v ./... exec garble test -v ./...
stdout 'ok\s+test/bar\s' stdout 'ok\s+test/bar\s'
stdout 'PASS.*TestFoo' stdout 'PASS.*TestFoo'
stdout 'PASS.*TestMain' stdout 'PASS.*TestMain'
@ -40,7 +40,7 @@ stdout 'ok\s+test/bar/sometest\s'
stdout 'ok\s+test/bar/exporttest\s' stdout 'ok\s+test/bar/exporttest\s'
# verify that non-build flags are kept # verify that non-build flags are kept
garble test -withflag -v exec garble test -withflag -v
stdout 'PASS.*TestWithFlag' stdout 'PASS.*TestWithFlag'
# verify with regular cmd/go; OriginalFuncName should appear # verify with regular cmd/go; OriginalFuncName should appear

@ -1,5 +1,5 @@
# Tiny mode # Tiny mode
garble -tiny build exec garble -tiny build
! binsubstr main$exe 'garble_main.go' 'fmt/print.go' ! binsubstr main$exe 'garble_main.go' 'fmt/print.go'
env GODEBUG='allocfreetrace=1,gcpacertrace=1,gctrace=1,inittrace=1,scavenge=1,scavtrace=1,scheddetail=1,schedtrace=10' env GODEBUG='allocfreetrace=1,gcpacertrace=1,gctrace=1,inittrace=1,scavenge=1,scavtrace=1,scheddetail=1,schedtrace=10'
! exec ./main$exe ! exec ./main$exe
@ -17,7 +17,7 @@ stderr 'funcStructExported false funcStructUnexported true'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
# Default mode # Default mode
garble build exec garble build
! exec ./main$exe ! exec ./main$exe
stderr '^caller: [0-9a-zA-Z_]+\.go [1-9]' stderr '^caller: [0-9a-zA-Z_]+\.go [1-9]'
stderr '^recovered: ya like jazz?' stderr '^recovered: ya like jazz?'

@ -1,4 +1,4 @@
garble build exec garble build
! binsubstr main$exe ${WORK} 'garble_main.go' 'GenericFunc' 'GenericVector' 'PredeclaredSignedInteger' 'StringableSignedInteger' 'CombineEmbeds' 'GenericParam' ! binsubstr main$exe ${WORK} 'garble_main.go' 'GenericFunc' 'GenericVector' 'PredeclaredSignedInteger' 'StringableSignedInteger' 'CombineEmbeds' 'GenericParam'
-- go.mod -- -- go.mod --
module test/main module test/main

Loading…
Cancel
Save