forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_configurations_test.go
More file actions
143 lines (112 loc) · 4.4 KB
/
test_configurations_test.go
File metadata and controls
143 lines (112 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package workspace
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetCommand(t *testing.T) {
testConfig, ok := TestConfigurations["elixir"]
assert.True(t, ok, "unexpectedly unable to find elixir test config")
cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
assert.Equal(t, cmd, "mix test")
}
func TestWindowsCommands(t *testing.T) {
testConfig, ok := TestConfigurations["cobol"]
assert.True(t, ok, "unexpectedly unable to find cobol test config")
cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
if runtime.GOOS == "windows" {
assert.Contains(t, cmd, ".ps1")
assert.NotContains(t, cmd, ".sh")
} else {
assert.Contains(t, cmd, ".sh")
assert.NotContains(t, cmd, ".ps1")
}
}
func TestGetCommandMissingConfig(t *testing.T) {
testConfig, ok := TestConfigurations["ruby"]
assert.True(t, ok, "unexpectedly unable to find ruby test config")
_, err := testConfig.GetTestCommand()
assert.Error(t, err)
// any assertions about this error message have to work across all platforms, so be vague
// unix: ".exercism/config.json: no such file or directory"
// windows: "open .exercism\config.json: The system cannot find the path specified."
assert.Contains(t, err.Error(), filepath.Join(".exercism", "config.json:"))
}
func TestIncludesSolutionAndTestFilesInCommand(t *testing.T) {
testConfig, ok := TestConfigurations["prolog"]
assert.True(t, ok, "unexpectedly unable to find prolog test config")
// this creates a config file in the test directory and removes it
dir := filepath.Join(".", ".exercism")
defer os.RemoveAll(dir)
err := os.Mkdir(dir, os.ModePerm)
assert.NoError(t, err)
f, err := os.Create(filepath.Join(dir, "config.json"))
assert.NoError(t, err)
defer f.Close()
_, err = f.WriteString(`{ "blurb": "Learn about the basics of Prolog by following a lasagna recipe.", "authors": ["iHiD", "pvcarrera"], "files": { "solution": ["lasagna.pl"], "test": ["lasagna_tests.plt"] } } `)
assert.NoError(t, err)
cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
assert.Equal(t, cmd, "swipl -f lasagna.pl -s lasagna_tests.plt -g run_tests,halt -t 'halt(1)'")
}
func TestIncludesTestFilesInCommand(t *testing.T) {
testConfig, ok := TestConfigurations["ruby"]
assert.True(t, ok, "unexpectedly unable to find ruby test config")
// this creates a config file in the test directory and removes it
dir := filepath.Join(".", ".exercism")
defer os.RemoveAll(dir)
err := os.Mkdir(dir, os.ModePerm)
assert.NoError(t, err)
f, err := os.Create(filepath.Join(dir, "config.json"))
assert.NoError(t, err)
defer f.Close()
_, err = f.WriteString(`{ "blurb": "Learn about the basics of Ruby by following a lasagna recipe.", "authors": ["iHiD", "pvcarrera"], "files": { "solution": ["lasagna.rb"], "test": ["lasagna_test.rb", "some_other_file.rb"], "exemplar": [".meta/exemplar.rb"] } } `)
assert.NoError(t, err)
cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
assert.Equal(t, cmd, "ruby lasagna_test.rb some_other_file.rb")
}
func TestRustHasTrailingDashes(t *testing.T) {
testConfig, ok := TestConfigurations["rust"]
assert.True(t, ok, "unexpectedly unable to find rust test config")
cmd, err := testConfig.GetTestCommand()
assert.NoError(t, err)
assert.True(t, strings.HasSuffix(cmd, "--"), "rust's test command should have trailing dashes")
}
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")
}