diff --git a/src/build/Matrix.go b/src/build/Matrix.go new file mode 100644 index 0000000..b056eb5 --- /dev/null +++ b/src/build/Matrix.go @@ -0,0 +1,16 @@ +package build + +// Matrix calls the given function with every possible combination of operating systems and architectures. +func (b *Build) Matrix(call func(*Build)) { + systems := []OS{Linux, Mac, Windows} + architectures := []Arch{ARM, X86} + + for _, os := range systems { + b.OS = os + + for _, arch := range architectures { + b.Arch = arch + call(b) + } + } +} \ No newline at end of file diff --git a/src/linker/WriteFile_test.go b/src/linker/WriteFile_test.go deleted file mode 100644 index 73f4578..0000000 --- a/src/linker/WriteFile_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package linker_test - -import ( - "os" - "path/filepath" - "testing" - - "git.urbach.dev/cli/q/src/build" - "git.urbach.dev/cli/q/src/compiler" - "git.urbach.dev/cli/q/src/linker" - "git.urbach.dev/go/assert" -) - -func TestWriteFile(t *testing.T) { - tmpDir := filepath.Join(os.TempDir(), "q", "tests") - err := os.MkdirAll(tmpDir, 0o755) - assert.Nil(t, err) - - fromPath := "../../examples/hello/hello.q" - contents, err := os.ReadFile(fromPath) - assert.Nil(t, err) - - toPath := filepath.Join(tmpDir, "hello.q") - err = os.WriteFile(toPath, contents, 0o755) - assert.Nil(t, err) - - b := build.New(toPath) - env, err := compiler.Compile(b) - assert.Nil(t, err) - - b.Arch = build.ARM - err = linker.WriteFile(b.Executable(), b, env) - assert.Nil(t, err) - - b.Arch = build.X86 - err = linker.WriteFile(b.Executable(), b, env) - assert.Nil(t, err) -} \ No newline at end of file diff --git a/src/linker/Write_test.go b/src/linker/Write_test.go new file mode 100644 index 0000000..bbde817 --- /dev/null +++ b/src/linker/Write_test.go @@ -0,0 +1,23 @@ +package linker_test + +import ( + "testing" + + "git.urbach.dev/cli/q/src/build" + "git.urbach.dev/cli/q/src/compiler" + "git.urbach.dev/cli/q/src/exe" + "git.urbach.dev/cli/q/src/linker" + "git.urbach.dev/go/assert" +) + +func TestWrite(t *testing.T) { + b := build.New("../../examples/hello") + + b.Matrix(func(b *build.Build) { + env, err := compiler.Compile(b) + assert.Nil(t, err) + + writer := &exe.Discard{} + linker.Write(writer, b, env) + }) +} \ No newline at end of file diff --git a/src/ssa2asm/Compiler_test.go b/src/ssa2asm/Compiler_test.go index d8b5f50..a9adadc 100644 --- a/src/ssa2asm/Compiler_test.go +++ b/src/ssa2asm/Compiler_test.go @@ -10,16 +10,9 @@ import ( func TestHelloExample(t *testing.T) { b := build.New("../../examples/hello") - systems := []build.OS{build.Linux, build.Mac, build.Windows} - architectures := []build.Arch{build.ARM, build.X86} - for _, os := range systems { - b.OS = os - - for _, arch := range architectures { - b.Arch = arch - _, err := compiler.Compile(b) - assert.Nil(t, err) - } - } + b.Matrix(func(b *build.Build) { + _, err := compiler.Compile(b) + assert.Nil(t, err) + }) } \ No newline at end of file