aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-04-06 14:15:42 +0200
committerRon Evans <[email protected]>2021-04-09 18:33:48 +0200
commitea8f7ba1f9b1e69a21c36ba3f7ed81097ea5e79f (patch)
tree38037c23c66a0ca7f455642b593e7f534bdff82e
parent0ffe5ac2fac2c2c91a213968db521516c0e2b9f6 (diff)
downloadtinygo-ea8f7ba1f9b1e69a21c36ba3f7ed81097ea5e79f.tar.gz
tinygo-ea8f7ba1f9b1e69a21c36ba3f7ed81097ea5e79f.zip
main: add tests for less common build configurations
Don't run the entire test suite for these options, as that would quickly explode the testing time (making it less likely people actually run it). Instead, run just one test for each configuration that should check for most issues.
-rw-r--r--main_test.go54
1 files changed, 42 insertions, 12 deletions
diff --git a/main_test.go b/main_test.go
index 0172bd02c..9f6d777cb 100644
--- a/main_test.go
+++ b/main_test.go
@@ -113,6 +113,32 @@ func TestCompiler(t *testing.T) {
runPlatTests("wasi", tests, t)
})
}
+
+ // Test a few build options.
+ t.Run("build-options", func(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ // These tests assume a host that is supported by TinyGo.
+ t.Skip("can't test build options on Windows")
+ }
+ t.Parallel()
+
+ // Test with few optimizations enabled (no inlining, etc).
+ t.Run("opt=1", func(t *testing.T) {
+ t.Parallel()
+ runTestWithConfig("stdlib.go", "", t, &compileopts.Options{
+ Opt: "1",
+ }, nil)
+ })
+
+ // Test with only the bare minimum of optimizations enabled.
+ // TODO: fix this for stdlib.go, which currently fails.
+ t.Run("opt=0", func(t *testing.T) {
+ t.Parallel()
+ runTestWithConfig("print.go", "", t, &compileopts.Options{
+ Opt: "0",
+ }, nil)
+ })
+ })
}
func runPlatTests(target string, tests []string, t *testing.T) {
@@ -150,6 +176,21 @@ func runBuild(src, out string, opts *compileopts.Options) error {
}
func runTest(name, target string, t *testing.T, environmentVars []string) {
+ options := &compileopts.Options{
+ Target: target,
+ Opt: "z",
+ PrintIR: false,
+ DumpSSA: false,
+ VerifyIR: true,
+ Debug: true,
+ PrintSizes: "",
+ WasmAbi: "",
+ }
+ runTestWithConfig(name, target, t, options, environmentVars)
+}
+
+func runTestWithConfig(name, target string, t *testing.T, options *compileopts.Options, environmentVars []string) {
+ // Get the expected output for this test.
// Note: not using filepath.Join as it strips the path separator at the end
// of the path.
path := TESTDATA + "/" + name
@@ -176,19 +217,8 @@ func runTest(name, target string, t *testing.T, environmentVars []string) {
}()
// Build the test binary.
- config := &compileopts.Options{
- Target: target,
- Opt: "z",
- PrintIR: false,
- DumpSSA: false,
- VerifyIR: true,
- Debug: true,
- PrintSizes: "",
- WasmAbi: "",
- }
-
binary := filepath.Join(tmpdir, "test")
- err = runBuild("./"+path, binary, config)
+ err = runBuild("./"+path, binary, options)
if err != nil {
printCompilerError(t.Log, err)
t.Fail()