Basic tests for the compiler. Build some Go files and compare the output with the expected LLVM IR for regression testing.
(t *testing.T)
| 26 | // Basic tests for the compiler. Build some Go files and compare the output with |
| 27 | // the expected LLVM IR for regression testing. |
| 28 | func TestCompiler(t *testing.T) { |
| 29 | t.Parallel() |
| 30 | |
| 31 | // Determine Go minor version (e.g. 16 in go1.16.3). |
| 32 | _, goMinor, err := goenv.GetGorootVersion() |
| 33 | if err != nil { |
| 34 | t.Fatal("could not read Go version:", err) |
| 35 | } |
| 36 | |
| 37 | // Determine which tests to run, depending on the Go and LLVM versions. |
| 38 | tests := []testCase{ |
| 39 | {"basic.go", "", ""}, |
| 40 | {"pointer.go", "", ""}, |
| 41 | {"slice.go", "", ""}, |
| 42 | {"string.go", "", ""}, |
| 43 | {"float.go", "", ""}, |
| 44 | {"interface.go", "", ""}, |
| 45 | {"func.go", "", ""}, |
| 46 | {"defer.go", "cortex-m-qemu", ""}, |
| 47 | {"pragma.go", "", ""}, |
| 48 | {"goroutine.go", "wasm", "asyncify"}, |
| 49 | {"goroutine.go", "cortex-m-qemu", "tasks"}, |
| 50 | {"channel.go", "", ""}, |
| 51 | {"gc.go", "", ""}, |
| 52 | {"zeromap.go", "", ""}, |
| 53 | } |
| 54 | if goMinor >= 20 { |
| 55 | tests = append(tests, testCase{"go1.20.go", "", ""}) |
| 56 | } |
| 57 | if goMinor >= 21 { |
| 58 | tests = append(tests, testCase{"go1.21.go", "", ""}) |
| 59 | } |
| 60 | |
| 61 | for _, tc := range tests { |
| 62 | name := tc.file |
| 63 | targetString := "wasm" |
| 64 | if tc.target != "" { |
| 65 | targetString = tc.target |
| 66 | name += "-" + tc.target |
| 67 | } |
| 68 | if tc.scheduler != "" { |
| 69 | name += "-" + tc.scheduler |
| 70 | } |
| 71 | |
| 72 | t.Run(name, func(t *testing.T) { |
| 73 | options := &compileopts.Options{ |
| 74 | Target: targetString, |
| 75 | } |
| 76 | if tc.scheduler != "" { |
| 77 | options.Scheduler = tc.scheduler |
| 78 | } |
| 79 | |
| 80 | mod, errs := testCompilePackage(t, options, tc.file) |
| 81 | if errs != nil { |
| 82 | for _, err := range errs { |
| 83 | t.Error(err) |
| 84 | } |
| 85 | return |
nothing calls this directly
no test coverage detected