From c256daceb096967963ef29e4ac7b2465e2e993f3 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 25 Jun 2017 20:17:53 +0100 Subject: [PATCH] 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. --- prog/weaver/main_test.go | 5 +++-- testing/util.go | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/prog/weaver/main_test.go b/prog/weaver/main_test.go index 1873f4a3..c9cfe8b3 100644 --- a/prog/weaver/main_test.go +++ b/prog/weaver/main_test.go @@ -7,6 +7,7 @@ import ( ) func TestMain(t *testing.T) { - weavetest.TrimTestArgs() - main() + if weavetest.TrimTestArgs() { + main() + } } diff --git a/testing/util.go b/testing/util.go index aed7ae31..f87dba65 100644 --- a/testing/util.go +++ b/testing/util.go @@ -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 }