Skip to content

Commit

Permalink
Fix tinygo-org#4421 add tests for 'build' and 'run' ('test' already c…
Browse files Browse the repository at this point in the history
…hanges directory)

Signed-off-by: Roger Standridge <[email protected]>
  • Loading branch information
archie2x committed Sep 11, 2024
1 parent 628e107 commit 9c88472
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/testing/chdir/chdir.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 9c88472

Please sign in to comment.