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

Function runTest

cmd/test.go:26–68  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

24}
25
26func runTest(args []string) error {
27 track, err := getTrack()
28 if err != nil {
29 return err
30 }
31
32 testConf, ok := workspace.TestConfigurations[track]
33
34 if !ok {
35 return fmt.Errorf("the \"%s\" track does not yet support running tests using the Exercism CLI. Please see HELP.md for testing instructions", track)
36 }
37
38 command, err := testConf.GetTestCommand()
39 if err != nil {
40 return err
41 }
42 cmdParts := strings.Split(command, " ")
43
44 // pass args/flags to this command down to the test handler
45 if len(args) > 0 {
46 cmdParts = append(cmdParts, args...)
47 }
48
49 fmt.Printf("Running tests via `%s`\n\n", strings.Join(cmdParts, " "))
50 exerciseTestCmd := exec.Command(cmdParts[0], cmdParts[1:]...)
51
52 // pipe output directly out, preserving any color
53 exerciseTestCmd.Stdout = os.Stdout
54 exerciseTestCmd.Stderr = os.Stderr
55
56 err = exerciseTestCmd.Run()
57 if err != nil {
58 // unclear what other errors would pop up here, but it pays to be defensive
59 if exitErr, ok := err.(*exec.ExitError); ok {
60 exitCode := exitErr.ExitCode()
61 // if subcommand returned a non-zero exit code, exit with the same
62 os.Exit(exitCode)
63 } else {
64 log.Fatalf("Failed to get error from failed subcommand: %v", err)
65 }
66 }
67 return nil
68}
69
70func getTrack() (string, error) {
71 metadata, err := workspace.NewExerciseMetadata(".")

Callers 1

test.goFile · 0.85

Calls 2

getTrackFunction · 0.85
GetTestCommandMethod · 0.80

Tested by

no test coverage detected