don't panic when TestMain is invoked as a regular test
Just no-op instead. This change is necessary because previously a recent build-tools change no longer excludes prog/* from unit testing since other projects actually do have genuine tests under there.
This commit is contained in:
1 parent
73b29050b9
commit
c256daceb0
2 files changed
+8
-5
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
weavetest.TrimTestArgs()
|
||||
main()
|
||||
if weavetest.TrimTestArgs() {
|
||||
main()
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -35,8 +35,9 @@ func stackTrace(all bool) string {
|
||||
return string(buf[:stacklen])
|
||||
}
|
||||
|
||||
// TrimTestArgs finds the first -- in os.Args and trim all args before that
|
||||
func TrimTestArgs() {
|
||||
// TrimTestArgs finds the first -- in os.Args and trim all args before
|
||||
// that, returning true when a -- was in fact found.
|
||||
func TrimTestArgs() bool {
|
||||
i, l := 0, len(os.Args)
|
||||
for ; i < l; i++ {
|
||||
if os.Args[i] == "--" {
|
||||
@@ -44,7 +45,8 @@ func TrimTestArgs() {
|
||||
}
|
||||
}
|
||||
if i == l {
|
||||
panic("Specify weave args after --")
|
||||
return false
|
||||
}
|
||||
os.Args = append(os.Args[:1], os.Args[i+1:l]...)
|
||||
return true
|
||||
}
|
||||
Reference in new issue
Block a user