transform: move tests to transform_test package

This allows for adding more advanced tests, for example tests that use
the compiler package so that test sources can be written in Go instead
of LLVM IR.
Этот коммит содержится в:
Ayke van Laethem 2021-04-22 12:44:22 +02:00 коммит произвёл Ron Evans
родитель 25f3adb47e
коммит 404b65941a
13 изменённых файлов: 44 добавлений и 28 удалений

Просмотреть файл

@ -1,10 +1,12 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
)
func TestAllocs(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/allocs", OptimizeAllocs)
testTransform(t, "testdata/allocs", transform.OptimizeAllocs)
}

Просмотреть файл

@ -1,10 +1,12 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
)
func TestFuncLowering(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/func-lowering", LowerFuncValues)
testTransform(t, "testdata/func-lowering", transform.LowerFuncValues)
}

Просмотреть файл

@ -1,21 +1,22 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
func TestAddGlobalsBitmap(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/gc-globals", func(mod llvm.Module) {
AddGlobalsBitmap(mod)
transform.AddGlobalsBitmap(mod)
})
}
func TestMakeGCStackSlots(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/gc-stackslots", func(mod llvm.Module) {
MakeGCStackSlots(mod)
transform.MakeGCStackSlots(mod)
})
}

Просмотреть файл

@ -1,14 +1,15 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
func TestApplyFunctionSections(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/globals-function-sections", func(mod llvm.Module) {
ApplyFunctionSections(mod)
transform.ApplyFunctionSections(mod)
})
}

Просмотреть файл

@ -1,14 +1,16 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
func TestGoroutineLowering(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/coroutines", func(mod llvm.Module) {
err := LowerCoroutines(mod, false)
err := transform.LowerCoroutines(mod, false)
if err != nil {
panic(err)
}

Просмотреть файл

@ -1,15 +1,16 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
func TestInterfaceLowering(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/interface", func(mod llvm.Module) {
err := LowerInterfaces(mod, 0)
err := transform.LowerInterfaces(mod, 0)
if err != nil {
t.Error(err)
}

Просмотреть файл

@ -1,8 +1,9 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@ -11,7 +12,7 @@ func TestInterruptLowering(t *testing.T) {
for _, subtest := range []string{"avr", "cortexm"} {
t.Run(subtest, func(t *testing.T) {
testTransform(t, "testdata/interrupt-"+subtest, func(mod llvm.Module) {
errs := LowerInterrupts(mod, 0)
errs := transform.LowerInterrupts(mod, 0)
if len(errs) != 0 {
t.Fail()
for _, err := range errs {

Просмотреть файл

@ -1,8 +1,9 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@ -10,7 +11,7 @@ func TestOptimizeMaps(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/maps", func(mod llvm.Module) {
// Run optimization pass.
OptimizeMaps(mod)
transform.OptimizeMaps(mod)
// Run an optimization pass, to clean up the result.
// This shows that all code related to the map is really eliminated.

Просмотреть файл

@ -1,10 +1,12 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
)
func TestReplacePanicsWithTrap(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/panic", ReplacePanicsWithTrap)
testTransform(t, "testdata/panic", transform.ReplacePanicsWithTrap)
}

Просмотреть файл

@ -1,8 +1,9 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@ -10,7 +11,7 @@ func TestOptimizeStringToBytes(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/stringtobytes", func(mod llvm.Module) {
// Run optimization pass.
OptimizeStringToBytes(mod)
transform.OptimizeStringToBytes(mod)
})
}
@ -18,7 +19,7 @@ func TestOptimizeStringEqual(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/stringequal", func(mod llvm.Module) {
// Run optimization pass.
OptimizeStringEqual(mod)
transform.OptimizeStringEqual(mod)
})
}
@ -26,6 +27,6 @@ func TestOptimizeReflectImplements(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/reflect-implements", func(mod llvm.Module) {
// Run optimization pass.
OptimizeReflectImplements(mod)
transform.OptimizeReflectImplements(mod)
})
}

Просмотреть файл

@ -1,9 +1,10 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@ -11,7 +12,7 @@ func TestCreateStackSizeLoads(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/stacksize", func(mod llvm.Module) {
// Run optimization pass.
CreateStackSizeLoads(mod, &compileopts.Config{
transform.CreateStackSizeLoads(mod, &compileopts.Config{
Target: &compileopts.TargetSpec{
DefaultStackSize: 1024,
},

Просмотреть файл

@ -1,4 +1,4 @@
package transform
package transform_test
// This file defines some helper functions for testing transforms.

Просмотреть файл

@ -1,8 +1,9 @@
package transform
package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@ -10,7 +11,7 @@ func TestWasmABI(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/wasm-abi", func(mod llvm.Module) {
// Run ABI change pass.
err := ExternalInt64AsPtr(mod)
err := transform.ExternalInt64AsPtr(mod)
if err != nil {
t.Errorf("failed to change wasm ABI: %v", err)
}