~mna/snow unlisted

snow/pkg/semantic/typecheck_pass_test.go -rw-r--r-- 1.1 KiB
424066c5Martin Angers doc: v0.0.5 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package semantic_test

import (
	"bytes"
	"flag"
	"path/filepath"
	"testing"

	"git.sr.ht/~mna/snow/pkg/internal/filetest"
	"git.sr.ht/~mna/snow/pkg/printer"
	"git.sr.ht/~mna/snow/pkg/scanner"
	"git.sr.ht/~mna/snow/pkg/semantic"
)

var testUpdateCheckTests = flag.Bool("test.update-check-tests", false, "If set, replace expected semantic check test results with actual results.")

func TestCheck(t *testing.T) {
	baseDir := "testdata"
	expectDir := filepath.Join(baseDir, "check")

	for _, fi := range filetest.SourceFiles(t, baseDir) {
		t.Run(fi.Name(), func(t *testing.T) {
			unit, err := semantic.Run(semantic.TypeCheckPass, filepath.Join(baseDir, fi.Name()))
			if unit == nil && err != nil {
				t.Fatal(err)
			}

			var ebuf bytes.Buffer
			scanner.PrintError(&ebuf, err)

			var buf bytes.Buffer
			pp := printer.Printer{W: &buf, Pos: printer.PosNone}
			for _, f := range unit.Files {
				_ = pp.PrintSemantic(f, unit.FileSet.File(f.Pos()))
			}

			filetest.DiffOutput(t, fi, buf.String(), expectDir, testUpdateCheckTests)
			filetest.DiffErrors(t, fi, ebuf.String(), expectDir, testUpdateCheckTests)
		})
	}
}