Skip to content

Commit

Permalink
Fix #4421 add tests for 'build' and 'run' ('test' already changes dir…
Browse files Browse the repository at this point in the history
…ectory)

Signed-off-by: Roger Standridge <[email protected]>
  • Loading branch information
archie2x committed Sep 10, 2024
1 parent 628e107 commit d6cdc7a
Show file tree
Hide file tree
Showing 2 changed files with 32 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
22 changes: 22 additions & 0 deletions tests/testing/chdir/chdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"log"
"os"
)

/*
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 cwd != expectDir {
log.Fatal("expected:\"%v\" != os.Getwd():\"%v\"", expectDir, cwd)
}
}

0 comments on commit d6cdc7a

Please sign in to comment.