File: testutil_test.go

package info (click to toggle)
golang-github-dop251-goja 0.0~git20250630.0.58d95d8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,264 kB
  • sloc: javascript: 454; perl: 184; makefile: 6; sh: 1
file content (49 lines) | stat: -rw-r--r-- 953 bytes parent folder | download
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
42
43
44
45
46
47
48
49
package parser

import (
	"fmt"
	"path/filepath"
	"runtime"
	"testing"
)

// Quick and dirty replacement for terst

func tt(t *testing.T, f func()) {
	defer func() {
		if x := recover(); x != nil {
			pcs := make([]uintptr, 16)
			pcs = pcs[:runtime.Callers(1, pcs)]
			frames := runtime.CallersFrames(pcs)
			var file string
			var line int
			for {
				frame, more := frames.Next()
				// The line number here must match the line where f() is called (see below)
				if frame.Line == 40 && filepath.Base(frame.File) == "testutil_test.go" {
					break
				}

				if !more {
					break
				}
				file, line = frame.File, frame.Line
			}
			if line > 0 {
				t.Errorf("Error at %s:%d: %v", filepath.Base(file), line, x)
			} else {
				t.Errorf("Error at <unknown>: %v", x)
			}
		}
	}()

	f()
}

func is(a, b interface{}) {
	as := fmt.Sprintf("%v", a)
	bs := fmt.Sprintf("%v", b)
	if as != bs {
		panic(fmt.Errorf("%+v(%T) != %+v(%T)", a, a, b, b))
	}
}