diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/testing.go | 9 | ||||
-rw-r--r-- | src/testing/testing_test.go | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index fee9d40b1..8429e9221 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -120,6 +120,15 @@ func Verbose() bool { return flagVerbose } +// String constant that is being set when running a test. +var testBinary string + +// Testing returns whether the program was compiled as a test, using "tinygo +// test". It returns false when built using "tinygo build", "tinygo flash", etc. +func Testing() bool { + return testBinary == "1" +} + // flushToParent writes c.output to the parent after first writing the header // with the given format and arguments. func (c *common) flushToParent(testName, format string, args ...interface{}) { diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go index 8a2586535..631a31341 100644 --- a/src/testing/testing_test.go +++ b/src/testing/testing_test.go @@ -195,3 +195,9 @@ func TestSetenv(t *testing.T) { } } } + +func TestTesting(t *testing.T) { + if !testing.Testing() { + t.Error("Expected testing.Testing() to return true while in a test") + } +} |