forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_configurations.go
251 lines (242 loc) · 5.36 KB
/
test_configurations.go
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package workspace
import (
"fmt"
"runtime"
"strings"
)
type TestConfiguration struct {
// The static portion of the test Command, which will be run for every test on this track. Examples include `cargo test` or `go test`.
// Might be empty if there are platform-specific versions
Command string
// Windows-specific test command. Mostly relevant for tests wrapped by shell invocations. Falls back to `Command` if we're not running windows or this is empty.
WindowsCommand string
}
func (c *TestConfiguration) GetTestCommand() (string, error) {
var cmd string
if runtime.GOOS == "windows" && c.WindowsCommand != "" {
cmd = c.WindowsCommand
} else {
cmd = c.Command
}
// pre-declare these so we can conditionally initialize them
var exerciseConfig *ExerciseConfig
var err error
if strings.Contains(cmd, "{{") {
// only read exercise's config.json if we need it
exerciseConfig, err = NewExerciseConfig(".")
if err != nil {
return "", err
}
}
if strings.Contains(cmd, "{{solution_files}}") {
if exerciseConfig == nil {
return "", fmt.Errorf("exerciseConfig not initialize before use")
}
solutionFiles, err := exerciseConfig.GetSolutionFiles()
if err != nil {
return "", err
}
cmd = strings.ReplaceAll(cmd, "{{solution_files}}", strings.Join(solutionFiles, " "))
}
if strings.Contains(cmd, "{{test_files}}") {
if exerciseConfig == nil {
return "", fmt.Errorf("exerciseConfig not initialize before use")
}
testFiles, err := exerciseConfig.GetTestFiles()
if err != nil {
return "", err
}
cmd = strings.ReplaceAll(cmd, "{{test_files}}", strings.Join(testFiles, " "))
}
return cmd, nil
}
// some tracks aren't (or won't be) implemented; every track is listed either way
var TestConfigurations = map[string]TestConfiguration{
"8th": {
Command: "8th -f test.8th",
},
// abap: tests are run via "ABAP Development Tools", not the CLI
"awk": {
Command: "bats {{test_files}}",
},
"ballerina": {
Command: "bal test",
},
"bash": {
Command: "bats {{test_files}}",
},
"c": {
Command: "make",
},
"cfml": {
Command: "box task run TestRunner",
},
"clojure": {
// chosen because the docs recommend `clj` by default and `lein` as optional
Command: "clj -X:test",
},
"cobol": {
Command: "bash test.sh",
WindowsCommand: "pwsh test.ps1",
},
"coffeescript": {
Command: "jasmine-node --coffee {{test_files}}",
},
// common-lisp: tests are loaded into a "running Lisp implementation", not the CLI directly
"cpp": {
Command: "make",
},
"crystal": {
Command: "crystal spec",
},
"csharp": {
Command: "dotnet test",
},
"d": {
// this always works even if the user installed DUB
Command: "dmd source/*.d -de -w -main -unittest",
},
"dart": {
Command: "dart test",
},
// delphi: tests are run via IDE
"elixir": {
Command: "mix test",
},
"elm": {
Command: "elm-test",
},
"emacs-lisp": {
Command: "emacs -batch -l ert -l {{test_files}} -f ert-run-tests-batch-and-exit",
},
"erlang": {
Command: "rebar3 eunit",
},
"fortran": {
Command: "make",
},
"fsharp": {
Command: "dotnet test",
},
"gleam": {
Command: "gleam test",
},
"go": {
Command: "go test",
},
"groovy": {
Command: "gradle test",
},
"haskell": {
Command: "stack test",
},
"java": {
Command: "gradle test",
},
"javascript": {
Command: "npm run test",
},
"jq": {
Command: "bats {{test_files}}",
},
"julia": {
Command: "julia runtests.jl",
},
"kotlin": {
Command: "./gradlew test",
WindowsCommand: "gradlew.bat test",
},
"lfe": {
Command: "make test",
},
"lua": {
Command: "busted",
},
"mips": {
Command: "java -jar /path/to/mars.jar nc runner.mips impl.mips",
},
"nim": {
Command: "nim r {{test_files}}",
},
// objective-c: tests are run via XCode. There's a CLI option (ruby gem `objc`), but the docs note that this is an inferior experience
"ocaml": {
Command: "make",
},
"perl5": {
Command: "prove .",
},
// pharo-smalltalk: tests are run via IDE
"php": {
Command: "phpunit {{test_files}}",
},
// plsql: test are run via a "mounted oracle db"
"powershell": {
Command: "Invoke-Pester",
},
"prolog": {
Command: "swipl -f {{solution_files}} -s {{test_files}} -g run_tests,halt -t 'halt(1)'",
},
"purescript": {
Command: "spago test",
},
"python": {
Command: "python3 -m pytest -o markers=task {{test_files}}",
},
"r": {
Command: "Rscript {{test_files}}",
},
"racket": {
Command: "raco test {{test_files}}",
},
"raku": {
Command: "prove6 {{test_files}}",
},
"reasonml": {
Command: "npm run test",
},
"red": {
Command: "red {{test_files}}",
},
"ruby": {
Command: "ruby {{test_files}}",
},
"rust": {
Command: "cargo test --",
},
"scala": {
Command: "sbt test",
},
// scheme: docs present 2 equally valid test methods (`make chez` and `make guile`). So I wasn't sure which to pick
"sml": {
Command: "poly -q --use {{test_files}}",
},
"swift": {
Command: "swift test",
},
"tcl": {
Command: "tclsh {{test_files}}",
},
"typescript": {
Command: "yarn test",
},
// unison: tests are run from an active UCM session
"vbnet": {
Command: "dotnet test",
},
// vimscript: tests are run from inside a vim session
"vlang": {
Command: "v -stats test run_test.v",
},
"wasm": {
Command: "npm run test",
},
"wren": {
Command: "wrenc {{test_files}}",
},
"x86-64-assembly": {
Command: "make",
},
"zig": {
Command: "zig test {{test_files}}",
},
}