env GOPRIVATE=test/main

# Check the binary with a given base64 encoded seed
garble -literals -seed=OQg9kACEECQ build
exec ./main$exe
cmp stderr main.stdout
! binsubstr main$exe 'teststring' 'teststringVar' 'imported var value' 'ImportedVar'

[short] stop # checking that the build is reproducible and random is slow

# Also check that the binary is reproducible.
# No packages should be rebuilt either, thanks to the build cache.
cp main$exe main_old$exe
rm main$exe
garble -literals -seed=OQg9kACEECQ= build -v
! stderr .
bincmp main$exe main_old$exe

# Also check that a different seed leads to a different binary.
# We can't know if caching happens here, because of previous test runs.
cp main$exe main_old$exe
rm main$exe
garble -literals -seed=NruiDmVz6/s build
! bincmp main$exe main_old$exe

# Use a random seed, which should always trigger a full build.
garble -literals -seed=random build -v
stderr .
exec ./main$exe
cmp stderr main.stdout
! binsubstr main$exe 'teststring' 'teststringVar' 'imported var value' 'ImportedVar'

# Also check that the random binary is not reproducible.
cp main$exe main_old$exe
rm main$exe
garble -literals -seed=random build -v
stderr .
! bincmp main$exe main_old$exe

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

import "test/main/imported"

var teststringVar = "teststring"

func main() {
	println(teststringVar)
	println(imported.ImportedVar)
}
-- imported/imported.go --
package imported

var ImportedVar = "imported var value"

-- main.stdout --
teststring
imported var value
