Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Faster tests from 80s to 4s on my laptop
Browse files Browse the repository at this point in the history
  • Loading branch information
lu4p committed Jun 30, 2020
1 parent 008a133 commit abb96b6
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 38 deletions.
27 changes: 27 additions & 0 deletions bincludegen/gen_test.go
Expand Up @@ -2,6 +2,7 @@ package bincludegen_test

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -22,8 +23,34 @@ var update = flag.Bool("u", false, "update testscript output files")
func TestScripts(t *testing.T) {
t.Parallel()

wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

data := `module test/main
replace github.com/lu4p/binclude => ` + filepath.Join(wd, "..") + `
require (
github.com/lu4p/binclude v1.0.0
)`

modPath := filepath.Join(wd, "go.mod.txt")
err = ioutil.WriteFile(modPath, []byte(data), 0644)
if err != nil {
t.Fatal(err)
}

p := testscript.Params{
Dir: filepath.Join("testdata", "scripts"),
Setup: func(env *testscript.Env) error {
os.Getwd()
env.Vars = append(env.Vars,
"MOD_PATH="+modPath,
)
return nil
},
Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
"bincmp": bincmp,
},
Expand Down
4 changes: 2 additions & 2 deletions bincludegen/testdata/scripts/absolute.txt
@@ -1,8 +1,8 @@
! binclude
cp $MOD_PATH go.mod

! go build

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/bincludeexists.txt
@@ -1,11 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stderr main.stderr

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/debug.txt
@@ -1,11 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stderr main.stderr

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/filetargetnames.txt
@@ -1,12 +1,10 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go run .
[linux] cmp stdout main.linux.stdout
[windows] cmp stdout main.windows.stdout
[darwin] cmp stdout main.darwin.stdout

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/fromfile.txt
@@ -1,11 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stderr main.stderr

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/gzip.txt
@@ -1,11 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude -gzip
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stdout main.stdout

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
3 changes: 0 additions & 3 deletions bincludegen/testdata/scripts/inaccessibleassets.txt
@@ -1,12 +1,9 @@
go get -u github.com/lu4p/binclude@master
[!windows] chmod 000 assets
[!windows] ! binclude
[!windows] chmod 755 assets
[!windows] chmod 000 assets/asset1.txt
[!windows] ! binclude

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
3 changes: 0 additions & 3 deletions bincludegen/testdata/scripts/inaccessiblego.txt
@@ -1,9 +1,6 @@
go get -u github.com/lu4p/binclude@master
[!windows] chmod 000 main.go
[!windows] ! binclude

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 1 addition & 3 deletions bincludegen/testdata/scripts/multiFiles.txt
@@ -1,11 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stderr main.stderr

-- go.mod --
module test/main
-- main.go --
package main

Expand Down
4 changes: 0 additions & 4 deletions bincludegen/testdata/scripts/nonexisting.txt
@@ -1,9 +1,5 @@
go get -u github.com/lu4p/binclude@master
! binclude

-- go.mod --
module test/main

-- main.go --
package main

Expand Down
5 changes: 1 addition & 4 deletions bincludegen/testdata/scripts/test.txt
@@ -1,12 +1,9 @@
go get -u github.com/lu4p/binclude@master
binclude
cp $MOD_PATH go.mod
go build
exec ./main$exe
cmp stderr main.stderr

-- go.mod --
module test/main

-- main.go --
package main

Expand Down
4 changes: 0 additions & 4 deletions bincludegen/testdata/scripts/unwritable.txt
@@ -1,10 +1,6 @@
go get -u github.com/lu4p/binclude@master
[!windows] chmod 544 .

[!windows] ! binclude

-- go.mod --
module test/main
-- main.go --
package main

Expand Down

0 comments on commit abb96b6

Please sign in to comment.