From 235188e457262b2f3471cd2fbf29a7c03920e1db Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 14 Aug 2024 13:41:22 +0200 Subject: [PATCH] Improved Windows support --- src/build/Build.go | 11 +++++++++-- tests/examples_test.go | 4 ++-- tests/programs_test.go | 13 +++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/build/Build.go b/src/build/Build.go index 2e740c6..cb221a4 100644 --- a/src/build/Build.go +++ b/src/build/Build.go @@ -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. diff --git a/tests/examples_test.go b/tests/examples_test.go index 63dd7f3..bb9e4fe 100644 --- a/tests/examples_test.go +++ b/tests/examples_test.go @@ -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) }) } } diff --git a/tests/programs_test.go b/tests/programs_test.go index a6b117f..986cf81 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -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)