mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 04:53:42 +00:00
testing: add Testing function
This is new in Go 1.21.
This commit is contained in:
committed by
Ron Evans
parent
215dd3f0be
commit
c25dd0a972
@@ -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{}) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user