reduce unnecessary std imports in tests

Since we have to recompile all dependencies, this reduces a substantial
amount of work, reducing 'go test -short' time from ~16s to ~12s on my
laptop.
pull/23/head
Daniel Martí 5 years ago
parent 56a1fd0257
commit e4b58b1452

@ -1,13 +1,13 @@
garble build garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
binsubstr main$exe 'privateAdd' 'PublicAdd' binsubstr main$exe 'privateAdd' 'PublicAdd'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
go build go build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
@ -15,16 +15,14 @@ module test/main
package main package main
import ( import (
"fmt"
"test/main/imported" "test/main/imported"
) )
func privateAdd(x, y int64) int64 func privateAdd(x, y int64) int64
func main() { func main() {
fmt.Println(privateAdd(1, 2)) println(privateAdd(1, 2))
fmt.Println(imported.PublicAdd(3, 4)) println(imported.PublicAdd(3, 4))
} }
-- main.s -- -- main.s --
TEXT ·privateAdd(SB),$0-24 TEXT ·privateAdd(SB),$0-24
@ -44,6 +42,6 @@ TEXT ·PublicAdd(SB),$0-24
ADDQ BP, BX ADDQ BP, BX
MOVQ BX, ret+16(FP) MOVQ BX, ret+16(FP)
RET RET
-- main.stdout -- -- main.stderr --
3 3
7 7

@ -1,13 +1,13 @@
garble build garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
binsubstr main$exe 'privateAdd' binsubstr main$exe 'privateAdd'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
go build go build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
@ -21,10 +21,8 @@ static int privateAdd(int a, int b) {
*/ */
import "C" import "C"
import "fmt"
func main() { func main() {
fmt.Println(C.privateAdd(C.int(1), C.int(2))) println(C.privateAdd(C.int(1), C.int(2)))
} }
-- main.stdout -- -- main.stderr --
3 3

@ -1,13 +1,13 @@
garble build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=test/main/imported.ExportedVar=replaced' garble build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=test/main/imported.ExportedVar=replaced'
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
! binsubstr main$exe 'unexportedVersion' ! binsubstr main$exe 'unexportedVersion'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
exec go build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=test/main/imported.ExportedVar=replaced' exec go build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=test/main/imported.ExportedVar=replaced'
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
binsubstr main$exe 'unexportedVersion' binsubstr main$exe 'unexportedVersion'
-- go.mod -- -- go.mod --
@ -16,21 +16,19 @@ module test/main
package main package main
import ( import (
"fmt"
"test/main/imported" "test/main/imported"
) )
var unexportedVersion = "unknown" var unexportedVersion = "unknown"
func main() { func main() {
fmt.Println("version:", unexportedVersion) println("version:", unexportedVersion)
fmt.Println("var:", imported.ExportedVar) println("var:", imported.ExportedVar)
} }
-- imported/imported.go -- -- imported/imported.go --
package imported package imported
var ExportedVar = "original" var ExportedVar = "original"
-- main.stdout -- -- main.stderr --
version: v1.0.0 version: v1.0.0
var: replaced var: replaced

@ -1,13 +1,13 @@
garble build garble build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
! binsubstr main$exe '(devel)' ! binsubstr main$exe '(devel)'
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
exec go build exec go build
exec ./main exec ./main
cmp stdout main.stdout-orig cmp stderr main.stderr-orig
binsubstr main$exe '(devel)' binsubstr main$exe '(devel)'
-- go.mod -- -- go.mod --
@ -15,15 +15,16 @@ module test/main
-- main.go -- -- main.go --
package main package main
import ( import "runtime/debug"
"fmt"
"runtime/debug"
)
func main() { func main() {
fmt.Println(debug.ReadBuildInfo()) if info, ok := debug.ReadBuildInfo(); ok {
println("version", info.Main.Version)
} else {
println("no version")
} }
-- main.stdout-orig -- }
&{test/main {test/main (devel) <nil>} []} true -- main.stderr-orig --
-- main.stdout -- version (devel)
<nil> false -- main.stderr --
no version

@ -7,7 +7,7 @@ binsubstr plugin.so 'PublicVar' 'PublicFunc'
# Note that we need -trimpath; see the caveat section in the README. # Note that we need -trimpath; see the caveat section in the README.
go build -trimpath go build -trimpath
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
binsubstr main$exe 'PublicVar' 'PublicFunc' binsubstr main$exe 'PublicVar' 'PublicFunc'
! binsubstr plugin.so 'privateFunc' ! binsubstr plugin.so 'privateFunc'
@ -17,18 +17,16 @@ go build -buildmode=plugin ./plugin
binsubstr plugin.so 'PublicVar' 'PublicFunc' 'privateFunc' binsubstr plugin.so 'PublicVar' 'PublicFunc' 'privateFunc'
go build go build
exec ./main exec ./main
cmp stdout main.stdout cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
-- plugin/main.go -- -- plugin/main.go --
package main package main
import "fmt"
var PublicVar int var PublicVar int
func privateFunc(n int) { fmt.Printf("Hello, number %d\n", n) } func privateFunc(n int) { println("Hello, number", n) }
func PublicFunc() { privateFunc(PublicVar) } func PublicFunc() { privateFunc(PublicVar) }
-- main.go -- -- main.go --
@ -52,5 +50,5 @@ func main() {
*v.(*int) = 7 *v.(*int) = 7
f.(func())() f.(func())()
} }
-- main.stdout -- -- main.stderr --
Hello, number 7 Hello, number 7

Loading…
Cancel
Save