This commit is contained in:
parent
64a80f6090
commit
e6a6be1181
4 changed files with 43 additions and 49 deletions
16
src/build/Matrix.go
Normal file
16
src/build/Matrix.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
|
||||||
}
|
|
23
src/linker/Write_test.go
Normal file
23
src/linker/Write_test.go
Normal file
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
|
@ -10,16 +10,9 @@ import (
|
||||||
|
|
||||||
func TestHelloExample(t *testing.T) {
|
func TestHelloExample(t *testing.T) {
|
||||||
b := build.New("../../examples/hello")
|
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.Matrix(func(b *build.Build) {
|
||||||
b.OS = os
|
_, err := compiler.Compile(b)
|
||||||
|
assert.Nil(t, err)
|
||||||
for _, arch := range architectures {
|
})
|
||||||
b.Arch = arch
|
|
||||||
_, err := compiler.Compile(b)
|
|
||||||
assert.Nil(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue