(args []string)
| 19 | } |
| 20 | |
| 21 | func realMain(args []string) int { |
| 22 | if len(args) != 2 { |
| 23 | fmt.Fprintf(os.Stderr, "Usage: hclspecsuite <tests-dir> <hcldec-file>\n") |
| 24 | return 2 |
| 25 | } |
| 26 | |
| 27 | testsDir := args[0] |
| 28 | hcldecPath := args[1] |
| 29 | |
| 30 | hcldecPath, err := exec.LookPath(hcldecPath) |
| 31 | if err != nil { |
| 32 | fmt.Fprintf(os.Stderr, "%s\n", err) |
| 33 | return 2 |
| 34 | } |
| 35 | |
| 36 | parser := hclparse.NewParser() |
| 37 | |
| 38 | color := term.IsTerminal(int(os.Stderr.Fd())) |
| 39 | w, _, err := term.GetSize(int(os.Stdout.Fd())) |
| 40 | if err != nil { |
| 41 | w = 80 |
| 42 | } |
| 43 | diagWr := hcl.NewDiagnosticTextWriter(os.Stderr, parser.Files(), uint(w), color) |
| 44 | var diagCount int |
| 45 | |
| 46 | runner := &Runner{ |
| 47 | parser: parser, |
| 48 | hcldecPath: hcldecPath, |
| 49 | baseDir: testsDir, |
| 50 | logBegin: func(name string, file *TestFile) { |
| 51 | fmt.Printf("- %s\n", name) |
| 52 | }, |
| 53 | logProblems: func(name string, file *TestFile, diags hcl.Diagnostics) { |
| 54 | if len(diags) != 0 { |
| 55 | fmt.Fprint(os.Stderr, "\n") |
| 56 | err := diagWr.WriteDiagnostics(diags) |
| 57 | if err != nil { |
| 58 | fmt.Fprintf(os.Stderr, "Error writing diagnostics: %s\n", err) |
| 59 | } |
| 60 | diagCount += len(diags) |
| 61 | } |
| 62 | fmt.Printf("- %s\n", name) |
| 63 | }, |
| 64 | } |
| 65 | diags := runner.Run() |
| 66 | |
| 67 | if len(diags) != 0 { |
| 68 | fmt.Fprintf(os.Stderr, "\n\n\n== Test harness problems:\n\n") |
| 69 | err := diagWr.WriteDiagnostics(diags) |
| 70 | if err != nil { |
| 71 | fmt.Fprintf(os.Stderr, "Error writing diagnostics: %s\n", err) |
| 72 | } |
| 73 | diagCount += len(diags) |
| 74 | } |
| 75 | |
| 76 | if diagCount > 0 { |
| 77 | return 2 |
| 78 | } |
no test coverage detected