Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion workspace/test_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (c *TestConfiguration) GetTestCommand() (string, error) {
}
cmd = strings.ReplaceAll(cmd, "{{test_files}}", strings.Join(testFiles, " "))
}
if strings.Contains(cmd, "{{slug}}") {
metadata, err := NewExerciseMetadata(".")
if err != nil {
return "", err
}
cmd = strings.ReplaceAll(cmd, "{{slug}}", metadata.ExerciseSlug)
}

return cmd, nil
}
Expand Down Expand Up @@ -152,7 +159,7 @@ var TestConfigurations = map[string]TestConfiguration{
Command: "stack test",
},
"idris": {
Command: "pack test `basename *.ipkg .ipkg`",
Command: "pack test {{slug}}",
},
"j": {
Command: `jconsole -js "exit echo unittest {{test_files}} [ load {{solution_files}}"`,
Expand Down
40 changes: 40 additions & 0 deletions workspace/test_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,43 @@ func TestRustHasTrailingDashes(t *testing.T) {

assert.True(t, strings.HasSuffix(cmd, "--"), "rust's test command should have trailing dashes")
}

func TestIdrisUsesCurrentDirectory(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestIdrisUsesCurrentDirectory(t *testing.T) {
func TestIdrisUsesExerciseSlug(t *testing.T) {

currentDir, err := os.Getwd()
assert.NoError(t, err)

tmpDir, err := os.MkdirTemp("", "solution")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)

em := &ExerciseMetadata{
Track: "idris",
ExerciseSlug: "bogus-exercise",
ID: "abc",
URL: "http://example.com",
Handle: "alice",
IsRequester: true,
Dir: tmpDir,
}
err = em.Write(tmpDir)
assert.NoError(t, err)

defer os.Chdir(currentDir)
err = os.Chdir(tmpDir)
assert.NoError(t, err)

exercismDir := filepath.Join(".", ".exercism")
f, err := os.Create(filepath.Join(exercismDir, "config.json"))
assert.NoError(t, err)
defer f.Close()

_, err = f.WriteString(`{ "files": { "solution": [ "src/BogusExercise.idr" ], "test": [ "test/src/Main.idr" ] } }`)
assert.NoError(t, err)

testConfig, ok := TestConfigurations["idris"]
assert.True(t, ok, "unexpectedly unable to find idris test config")

cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
assert.Equal(t, cmd, "pack test bogus-exercise")
}
Loading