MCPcopy
hub / github.com/tinygo-org/tinygo / TestCompiler

Function TestCompiler

compiler/compiler_test.go:28–129  ·  view source on GitHub ↗

Basic tests for the compiler. Build some Go files and compare the output with the expected LLVM IR for regression testing.

(t *testing.T)

Source from the content-addressed store, hash-verified

26// Basic tests for the compiler. Build some Go files and compare the output with
27// the expected LLVM IR for regression testing.
28func 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

Callers

nothing calls this directly

Calls 9

GetGorootVersionFunction · 0.92
testCompilePackageFunction · 0.85
ParallelMethod · 0.80
fuzzyEqualIRFunction · 0.70
FatalMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected