Skip to content

Commit 4a57aa7

Browse files
idris uses slug (#1192)
* idris uses slug * Obtain exercise slug from metadata * TestIdrisUsesExerciseSlug
1 parent 7580d02 commit 4a57aa7

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

workspace/test_configurations.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func (c *TestConfiguration) GetTestCommand() (string, error) {
5555
}
5656
cmd = strings.ReplaceAll(cmd, "{{test_files}}", strings.Join(testFiles, " "))
5757
}
58+
if strings.Contains(cmd, "{{slug}}") {
59+
metadata, err := NewExerciseMetadata(".")
60+
if err != nil {
61+
return "", err
62+
}
63+
cmd = strings.ReplaceAll(cmd, "{{slug}}", metadata.ExerciseSlug)
64+
}
5865

5966
return cmd, nil
6067
}
@@ -152,7 +159,7 @@ var TestConfigurations = map[string]TestConfiguration{
152159
Command: "stack test",
153160
},
154161
"idris": {
155-
Command: "pack test `basename *.ipkg .ipkg`",
162+
Command: "pack test {{slug}}",
156163
},
157164
"j": {
158165
Command: `jconsole -js "exit echo unittest {{test_files}} [ load {{solution_files}}"`,

workspace/test_configurations_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,43 @@ 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 TestIdrisUsesExerciseSlug(t *testing.T) {
106+
currentDir, err := os.Getwd()
107+
assert.NoError(t, err)
108+
109+
tmpDir, err := os.MkdirTemp("", "solution")
110+
assert.NoError(t, err)
111+
defer os.RemoveAll(tmpDir)
112+
113+
em := &ExerciseMetadata{
114+
Track: "idris",
115+
ExerciseSlug: "bogus-exercise",
116+
ID: "abc",
117+
URL: "http://example.com",
118+
Handle: "alice",
119+
IsRequester: true,
120+
Dir: tmpDir,
121+
}
122+
err = em.Write(tmpDir)
123+
assert.NoError(t, err)
124+
125+
defer os.Chdir(currentDir)
126+
err = os.Chdir(tmpDir)
127+
assert.NoError(t, err)
128+
129+
exercismDir := filepath.Join(".", ".exercism")
130+
f, err := os.Create(filepath.Join(exercismDir, "config.json"))
131+
assert.NoError(t, err)
132+
defer f.Close()
133+
134+
_, err = f.WriteString(`{ "files": { "solution": [ "src/BogusExercise.idr" ], "test": [ "test/src/Main.idr" ] } }`)
135+
assert.NoError(t, err)
136+
137+
testConfig, ok := TestConfigurations["idris"]
138+
assert.True(t, ok, "unexpectedly unable to find idris test config")
139+
140+
cmd, err := testConfig.GetTestCommand()
141+
assert.NoError(t, err)
142+
assert.Equal(t, cmd, "pack test bogus-exercise")
143+
}

0 commit comments

Comments
 (0)