Skip to content

Commit 3baa597

Browse files
idris uses slug
1 parent 7580d02 commit 3baa597

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

workspace/test_configurations.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package workspace
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
57
"runtime"
68
"strings"
79
)
@@ -55,6 +57,13 @@ func (c *TestConfiguration) GetTestCommand() (string, error) {
5557
}
5658
cmd = strings.ReplaceAll(cmd, "{{test_files}}", strings.Join(testFiles, " "))
5759
}
60+
if strings.Contains(cmd, "{{slug}}") {
61+
currentDir, err := os.Getwd()
62+
if err != nil {
63+
return "", fmt.Errorf("current directory invalid")
64+
}
65+
cmd = strings.ReplaceAll(cmd, "{{slug}}", filepath.Base(currentDir))
66+
}
5867

5968
return cmd, nil
6069
}
@@ -152,7 +161,7 @@ var TestConfigurations = map[string]TestConfiguration{
152161
Command: "stack test",
153162
},
154163
"idris": {
155-
Command: "pack test `basename *.ipkg .ipkg`",
164+
Command: "pack test {{slug}}",
156165
},
157166
"j": {
158167
Command: `jconsole -js "exit echo unittest {{test_files}} [ load {{solution_files}}"`,

workspace/test_configurations_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,35 @@ func TestRustHasTrailingDashes(t *testing.T) {
101101

102102
assert.True(t, strings.HasSuffix(cmd, "--"), "rust's test command should have trailing dashes")
103103
}
104+
105+
func TestIdrisUsesCurrentDirectory(t *testing.T) {
106+
currentDir, err := os.Getwd()
107+
assert.NoError(t, err)
108+
109+
exerciseDir := filepath.Join(currentDir, "hello-world")
110+
defer os.RemoveAll(exerciseDir)
111+
err = os.Mkdir(exerciseDir, os.ModePerm)
112+
assert.NoError(t, err)
113+
114+
defer os.Chdir(currentDir)
115+
err = os.Chdir(exerciseDir)
116+
assert.NoError(t, err)
117+
118+
exercismDir := filepath.Join(".", ".exercism")
119+
err = os.Mkdir(exercismDir, os.ModePerm)
120+
assert.NoError(t, err)
121+
122+
f, err := os.Create(filepath.Join(exercismDir, "config.json"))
123+
assert.NoError(t, err)
124+
defer f.Close()
125+
126+
_, err = f.WriteString(`{ "files": { "solution": [ "src/HelloWorld.idr" ], "test": [ "test/src/Main.idr" ] } }`)
127+
assert.NoError(t, err)
128+
129+
testConfig, ok := TestConfigurations["idris"]
130+
assert.True(t, ok, "unexpectedly unable to find idris test config")
131+
132+
cmd, err := testConfig.GetTestCommand()
133+
assert.NoError(t, err)
134+
assert.Equal(t, cmd, "pack test hello-world")
135+
}

0 commit comments

Comments
 (0)