diff --git a/GNUmakefile b/GNUmakefile index 7333a6ebc9..70a7c5f589 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -483,8 +483,17 @@ tinygo-baremetal: # regression test for #2666: e.g. encoding/hex must pass on baremetal $(TINYGO) test -target cortex-m-qemu encoding/hex +.PHONY: testchdir +testchdir: + # test 'build' command with{,out} -C argument + $(TINYGO) build -C tests/testing/chdir chdir.go && rm tests/testing/chdir/chdir + $(TINYGO) build ./tests/testing/chdir/chdir.go && rm chdir + # test 'run' command with{,out} -C argument + EXPECT_DIR=$(PWD)/tests/testing/chdir $(TINYGO) run -C tests/testing/chdir chdir.go + EXPECT_DIR=$(PWD) $(TINYGO) run ./tests/testing/chdir/chdir.go + .PHONY: smoketest -smoketest: +smoketest: testchdir $(TINYGO) version $(TINYGO) targets > /dev/null # regression test for #2892 diff --git a/tests/testing/chdir/chdir.go b/tests/testing/chdir/chdir.go new file mode 100644 index 0000000000..9539738503 --- /dev/null +++ b/tests/testing/chdir/chdir.go @@ -0,0 +1,27 @@ +package main + +import ( + "log" + "os" + "runtime" + "strings" +) + +/* +Test that this program is 'run' in expected directory. 'run' with expected +working-directory in 'EXPECT_DIR' environment variable' with{,out} a -C +argument. +*/ +func main() { + expectDir := os.Getenv("EXPECT_DIR") + cwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + if runtime.GOOS == "windows" { + strings.Replace(cwd, "\\", "/", -1) + } + if cwd != expectDir { + log.Fatal("expected:\"%v\" != os.Getwd():\"%v\"", expectDir, cwd) + } +}