You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/testdata/scripts/basic.txt

70 lines
2.0 KiB
Plaintext

# Check that the simplest use of garble works. Note the lack of a module or GOPRIVATE.
garble build main.go
exec ./main
cmp stderr main.stderr
# Ensure that -w and -s worked.
[!windows] [exec:readelf] exec readelf --section-headers main$exe
[!windows] [exec:readelf] ! stdout 'debug_info'
[!windows] [exec:readelf] ! stdout '\.symtab'
# The buildid needs to be missing from the binary. Otherwise, we leak
# information unnecessarily, which is made worse by how we use part of said
# buildid to obfuscate the main package.
[!windows] [exec:readelf] ! stdout 'buildid'
go tool buildid main$exe
! stdout .
# The build version needs to be missing too.
go version main$exe
stdout 'unknown'
! stdout 'go1'
! stdout 'devel'
! stdout $gofullversion
# The binary can't contain the version string either.
! binsubstr main$exe ${WORK@R} 'main.go' 'globalVar' 'globalFunc' $gofullversion
[short] stop # checking that the build is reproducible is slow
# Check that we fail if the user ran with -toolexec but without -trimpath.
! exec go build -a -toolexec=garble main.go
stderr 'should be used alongside -trimpath'
# Also check that the binary is reproducible.
cp main$exe main_old$exe
rm main$exe
garble build main.go
bincmp main$exe main_old$exe
# Check that the program works as expected without garble. No need to verify
# this when we run with -short.
exec go build main.go
exec ./main
cmp stderr main.stderr
# The default build includes DWARF and the symbol table.
[!windows] [exec:readelf] exec readelf --section-headers main$exe
[!windows] [exec:readelf] stdout 'debug_info'
[!windows] [exec:readelf] stdout '\.symtab'
# 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.
binsubstr main$exe 'main.go' 'globalVar' 'globalFunc' $gofullversion
[!windows] binsubstr main$exe ${WORK@R}
-- main.go --
package main
var globalVar = "global value"
func globalFunc() { println("global func body") }
func main() {
println(globalVar)
globalFunc()
}
-- main.stderr --
global value
global func body