MCPcopy Create free account
hub / github.com/exercism/cli / GetTestCommand

Method GetTestCommand

workspace/test_configurations.go:18–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18func (c *TestConfiguration) GetTestCommand() (string, error) {
19 var cmd string
20 if runtime.GOOS == "windows" && c.WindowsCommand != "" {
21 cmd = c.WindowsCommand
22 } else {
23 cmd = c.Command
24 }
25
26 // pre-declare these so we can conditionally initialize them
27 var exerciseConfig *ExerciseConfig
28 var err error
29
30 if strings.Contains(cmd, "{{") {
31 // only read exercise's config.json if we need it
32 exerciseConfig, err = NewExerciseConfig(".")
33 if err != nil {
34 return "", err
35 }
36 }
37
38 if strings.Contains(cmd, "{{solution_files}}") {
39 if exerciseConfig == nil {
40 return "", fmt.Errorf("exerciseConfig not initialize before use")
41 }
42 solutionFiles, err := exerciseConfig.GetSolutionFiles()
43 if err != nil {
44 return "", err
45 }
46 cmd = strings.ReplaceAll(cmd, "{{solution_files}}", strings.Join(solutionFiles, " "))
47 }
48 if strings.Contains(cmd, "{{test_files}}") {
49 if exerciseConfig == nil {
50 return "", fmt.Errorf("exerciseConfig not initialize before use")
51 }
52 testFiles, err := exerciseConfig.GetTestFiles()
53 if err != nil {
54 return "", err
55 }
56 cmd = strings.ReplaceAll(cmd, "{{test_files}}", strings.Join(testFiles, " "))
57 }
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 }
65
66 return cmd, nil
67}
68
69// some tracks aren't (or won't be) implemented; every track is listed either way
70var TestConfigurations = map[string]TestConfiguration{

Callers 8

TestGetCommandFunction · 0.80
TestWindowsCommandsFunction · 0.80
runTestFunction · 0.80

Calls 4

GetSolutionFilesMethod · 0.95
GetTestFilesMethod · 0.95
NewExerciseConfigFunction · 0.85
NewExerciseMetadataFunction · 0.85

Tested by 7

TestGetCommandFunction · 0.64
TestWindowsCommandsFunction · 0.64