Skip to content

Commit

Permalink
refactor: use fs to ensure pre_cmd is working
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemmahlees committed Sep 4, 2023
1 parent 21fde58 commit f56f994
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion air_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tmp_dir = "tmp"

[build]
# Array of commands to run before each build
pre_cmd = ["echo Hello","echo Air"]
pre_cmd = ["echo \"hello air\" > test.txt"]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
Expand Down
26 changes: 25 additions & 1 deletion runner/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,36 @@ func TestRerunWhenFileChanged(t *testing.T) {
}

func TestRunCommand(t *testing.T) {
// generate a random port
port, f := GetPort()
f()
t.Logf("port: %d", port)
tmpDir := initTestEnv(t, port)
// change dir to tmpDir
chdir(t, tmpDir)
engine, err := NewEngine("", true)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
err = engine.runCommand("echo Hello Air")
err = engine.runCommand("touch test.txt")
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
if _, err := os.Stat("./test.txt"); err != nil {
if os.IsNotExist(err) {
t.Fatalf("Should not be fail: %s.", err)
}
}
}

func TestRunPreCmd(t *testing.T) {
// generate a random port
port, f := GetPort()
f()
t.Logf("port: %d", port)
tmpDir := initTestEnv(t, port)
// change dir to tmpDir
chdir(t, tmpDir)
engine, err := NewEngine("", true)
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
Expand All @@ -205,6 +224,11 @@ func TestRunPreCmd(t *testing.T) {
if err != nil {
t.Fatalf("Should not be fail: %s.", err)
}
if _, err := os.Stat("./test.txt"); err != nil {
if os.IsNotExist(err) {
t.Fatalf("Should not be fail: %s.", err)
}
}
}

func TestRunBin(t *testing.T) {
Expand Down

0 comments on commit f56f994

Please sign in to comment.