Example #1
0
func TestBareFunc_panic(t *testing.T) {
	// runtime errors

	const N = 100000
	o := func(input string) {
		_, e := bareTestRun(t, input, N)
		if !arch8.IsErr(e, arch8.ErrPanic) {
			t.Log(input)
			t.Log(e)
			t.Error("should panic")
			return
		}
	}

	o("var a *int; var b=*a")
	o("var a *int=nil; var b=*a")
	o("var a *int; printInt(*a)")
	o("var a *bool; if *a {}")
	o("var s []int; i:=s[0]")
	o("var a [8]int; j:=-1; i:=a[j]")
	o("var a [8]int; i:=a[9]")
	o("var a [7]int; s:=a[0:0]; i:=s[0]")
	o("var a [7]int; s:=a[1:3]; i:=s[2]")
	o("var a [7]int; s:=a[:]; j:=-33; i:=s[j]")
	o("d:=0; a:=3/d")
	o("d:=0; a:=-3%d")
	o("var d [3]int; s:=d[:]; s=nil; printInt(s[1])")
}
Example #2
0
func TestSingleFilePanic(t *testing.T) {
	// runtime errors

	const N = 100000
	o := func(input string) {
		_, e := singleTestRun(t, input, N)
		if !arch8.IsErr(e, arch8.ErrPanic) {
			t.Log(input)
			t.Log(e)
			t.Error("should panic")
			return
		}
	}

	o("func main() { panic() }")
	o("func main() { var pa *int; printInt(*pa) }")
	o("struct A { a int }; func main() { var pa *A; b := pa.a; _ := b }")
	o("func main() { var a func(); a() }")
	o("func f() {}; func main() { var a func()=f; a=nil; a() }")
	o("func f(p *int) { printInt(*p) }; func main() { f(nil) }")
	o("struct A { p *int }; func main() { var a A; a.p=nil; *a.p=0 }")
}