| 45 | } |
| 46 | |
| 47 | func TestSpec(t *testing.T) { |
| 48 | suiteDir := filepath.Clean("../specsuite/tests") |
| 49 | harness := "./tmp_hclspecsuite" |
| 50 | hcldec := "./tmp_hcldec" |
| 51 | |
| 52 | cmd := exec.Command(harness, suiteDir, hcldec) |
| 53 | out, err := cmd.CombinedOutput() |
| 54 | if _, isExit := err.(*exec.ExitError); err != nil && !isExit { |
| 55 | t.Errorf("failed to run harness: %s", err) |
| 56 | } |
| 57 | failed := err != nil |
| 58 | |
| 59 | sc := bufio.NewScanner(bytes.NewReader(out)) |
| 60 | var lines []string |
| 61 | for sc.Scan() { |
| 62 | lines = append(lines, sc.Text()) |
| 63 | } |
| 64 | |
| 65 | i := 0 |
| 66 | for i < len(lines) { |
| 67 | cur := lines[i] |
| 68 | if strings.HasPrefix(cur, "- ") { |
| 69 | testName := cur[2:] |
| 70 | t.Run(testName, func(t *testing.T) { |
| 71 | i++ |
| 72 | for i < len(lines) { |
| 73 | cur := lines[i] |
| 74 | if strings.HasPrefix(cur, "- ") || strings.HasPrefix(cur, "==") { |
| 75 | return |
| 76 | } |
| 77 | t.Error(cur) |
| 78 | i++ |
| 79 | } |
| 80 | }) |
| 81 | } else { |
| 82 | if !strings.HasPrefix(cur, "==") { // not the "test harness problems" report, then |
| 83 | t.Log(cur) |
| 84 | } |
| 85 | i++ |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if failed { |
| 90 | t.Error("specsuite failed") |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | func goBuild(pkg, outFile string) error { |
| 95 | if runtime.GOOS == "windows" { |