TestCommand executes the test argument testPath is the path to the test suite config, it can be a dir or file ctx holds the command flags. If directory scanning is enabled with --dir, test filtering is not supported
(testPath string, ctx TestCommandContext)
| 25 | // ctx holds the command flags. If directory scanning is enabled with --dir, |
| 26 | // test filtering is not supported |
| 27 | func TestCommand(testPath string, ctx TestCommandContext) error { |
| 28 | if ctx.Workdir != "" { |
| 29 | err := os.Chdir(ctx.Workdir) |
| 30 | if err != nil { |
| 31 | return fmt.Errorf(err.Error()) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | if ctx.Verbose { |
| 36 | log.SetOutput(os.Stdout) |
| 37 | } |
| 38 | |
| 39 | overwriteConfigPath = ctx.Config |
| 40 | out = output.NewCliOutput(!ctx.NoColor) |
| 41 | |
| 42 | if testPath == "" { |
| 43 | testPath = CommanderFile |
| 44 | } |
| 45 | |
| 46 | var result runtime.Result |
| 47 | var err error |
| 48 | switch { |
| 49 | case ctx.Dir: |
| 50 | fmt.Println("Starting test against directory: " + testPath + "...") |
| 51 | fmt.Println("") |
| 52 | result, err = testDir(testPath, ctx.Filters) |
| 53 | case testPath == "-": |
| 54 | fmt.Println("Starting test from stdin...") |
| 55 | fmt.Println("") |
| 56 | result, err = testStdin(ctx.Filters) |
| 57 | case isURL(testPath): |
| 58 | fmt.Println("Starting test from " + testPath + "...") |
| 59 | fmt.Println("") |
| 60 | result, err = testURL(testPath, ctx.Filters) |
| 61 | default: |
| 62 | fmt.Println("Starting test file " + testPath + "...") |
| 63 | fmt.Println("") |
| 64 | result, err = testFile(testPath, "", ctx.Filters) |
| 65 | } |
| 66 | |
| 67 | if err != nil { |
| 68 | return fmt.Errorf(err.Error()) |
| 69 | } |
| 70 | |
| 71 | if !out.PrintSummary(result) && !ctx.Verbose { |
| 72 | return fmt.Errorf("Test suite failed, use --verbose for more detailed output") |
| 73 | } |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func testFile(filePath string, fileName string, filters runtime.Filters) (runtime.Result, error) { |
| 79 | s, err := getSuite(filePath, fileName) |
no test coverage detected