Improved Windows support

This commit is contained in:
Eduard Urbach 2024-08-14 13:41:22 +02:00
parent 9d0077d1a4
commit 235188e457
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 18 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"strings"
"git.akyoto.dev/cli/q/src/compiler"
"git.akyoto.dev/cli/q/src/config"
"git.akyoto.dev/cli/q/src/scanner"
)
@ -31,10 +32,16 @@ func (build *Build) Executable() string {
path, _ := filepath.Abs(build.Files[0])
if strings.HasSuffix(path, ".q") {
return fromFileName(path)
path = fromFileName(path)
} else {
return fromDirectoryName(path)
path = fromDirectoryName(path)
}
if config.TargetOS == "windows" {
path += ".exe"
}
return path
}
// fromDirectoryName returns the executable path based on the directory name.

View File

@ -33,12 +33,12 @@ func TestExamples(t *testing.T) {
t.Run(test.Name+"/debug", func(t *testing.T) {
config.ConstantFold = false
run(t, directory, "debug", test.Name, test.Input, test.Output, test.ExitCode)
run(t, directory, "debug", test.Input, test.Output, test.ExitCode)
})
t.Run(test.Name+"/release", func(t *testing.T) {
config.ConstantFold = true
run(t, directory, "release", test.Name, test.Input, test.Output, test.ExitCode)
run(t, directory, "release", test.Input, test.Output, test.ExitCode)
})
}
}

View File

@ -66,12 +66,12 @@ func TestPrograms(t *testing.T) {
t.Run(test.Name+"/debug", func(t *testing.T) {
config.ConstantFold = false
run(t, file, "debug", test.Name, test.Input, test.Output, test.ExitCode)
run(t, file, "debug", test.Input, test.Output, test.ExitCode)
})
t.Run(test.Name+"/release", func(t *testing.T) {
config.ConstantFold = true
run(t, file, "release", test.Name, test.Input, test.Output, test.ExitCode)
run(t, file, "release", test.Input, test.Output, test.ExitCode)
})
}
}
@ -90,16 +90,17 @@ func BenchmarkPrograms(b *testing.B) {
}
// run builds and runs the file to check if the output matches the expected output.
func run(t *testing.T, path string, version string, name string, input string, expectedOutput string, expectedExitCode int) {
func run(t *testing.T, path string, version string, input string, expectedOutput string, expectedExitCode int) {
b := build.New(path)
result, err := b.Run()
assert.Nil(t, err)
directory := filepath.Join(os.TempDir(), "q", version)
err = os.MkdirAll(directory, 0755)
tmpDir := filepath.Join(os.TempDir(), "q", version)
err = os.MkdirAll(tmpDir, 0755)
assert.Nil(t, err)
executable := filepath.Join(directory, name)
executable := b.Executable()
executable = filepath.Join(tmpDir, filepath.Base(executable))
err = result.WriteFile(executable)
assert.Nil(t, err)