コード例 #1
0
ファイル: testing.go プロジェクト: joao-parana/tardisgo
// An internal function but exported because it is cross-package; part of the implementation
// of the "go test" command.
func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) {
	//os.Exit(MainStart(matchString, tests, benchmarks, examples).Run())
	fmt.Println("testing.Main")
	if runtime.GOARCH != "" { // not running in the interpreter
		runtime.UnzipTestFS()
	}
	var t T
	names := []string{}
	for _, f := range tests {
		names = append(names, f.Name)
	}
	sort.Strings(names)
	for _, n := range names {
		for _, f := range tests {
			if n == f.Name {
				println("\nExecuting test:", n)
				f.F(&t)
			}
		}
	}
	if hadError {
		badExit()
	}
	if runtime.GOARCH == "" { // running the interpreter
		os.Exit(0)
	}
	hx.Call("(cpp || cs || java || macro || neko || php || python)", "Sys.exit", 1, 0)
	hx.Code("js", "untyped __js__('process.exit(0)');") // only works on Node
}
コード例 #2
0
ファイル: testing.go プロジェクト: joao-parana/tardisgo
func badExit() {
	if runtime.GOARCH == "" { // running the interpreter
		os.Exit(1)
	}
	hx.Call("(cpp || cs || java || macro || neko || php || python)", "Sys.exit", 1, 1)
	hx.Code("js", "untyped __js__('process.exit(1)');") // only works on Node
}
コード例 #3
0
ファイル: fd_nacl_haxe.go プロジェクト: joao-parana/tardisgo
// implemented in package runtime, to add time header on playground
func naclWrite(fd int, b []byte) int {
	switch fd {
	case 1, 2: // stdout,stderr
		hx.Call("", "Console.naclWrite", 1, string(b))
		return len(b)
	default:
		panic("syscall.naclWrite(" + hx.CallString("", "Std.string", 1, fd) + "," + string(b) + ")")
		return 0
	}
}
コード例 #4
0
func Exit(code int) (err error) {
	//_, _, e1 := Syscall(sys_exit, uintptr(code), 0, 0)
	//if e1 != 0 {
	//	err = e1
	//}
	hx.Call("(cpp || cs || java || macro || neko || php || python)", "Sys.exit", 1, code)
	if code == 0 {
		hx.Code("js", "untyped __js__('process.exit(0)');") // only works on Node
	} else { // all non-zero values return as 1
		hx.Code("js", "untyped __js__('process.exit(1)');") // only works on Node
	}
	panic("syscall.Exit(" + hx.CallString("", "Std.string", 1, code) + ")")
	return
}
コード例 #5
0
ファイル: tgotypes.go プロジェクト: henrylee2cn/tardisgo
func assertableTo(vid, tid int) bool {
	// id equality test done in Haxe
	if vid < 1 || vid >= len(TypeTable) { // entry 0 is always nil
		hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.assertableTo() tested type id out of range")
	}
	V := TypeTable[vid]
	if tid < 1 || tid >= len(TypeTable) { // entry 0 is always nil
		hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.assertableTo() interface type id out of range")
	}
	T := TypeTable[tid]
	ret := implements(T, V, false)
	/*
		// NOTE may not work properly in all circumstances yet, so test code retained
		ans := hx.CallBool("", "TypeAssert.assertableTo", 2, vid, tid)
		if ret != ans {
			println("DEBUG assertableTo wrong answer for T,V= ",
				*(T.string), T.kind&kindMask == Interface, tid,
				*(V.string), V.kind&kindMask == Interface, vid)
			implements(T, V, true)
			return ans
		}
	*/
	return ret
}
コード例 #6
0
ファイル: tgotypes.go プロジェクト: henrylee2cn/tardisgo
func getMethod(tid int, path, name string) uintptr {
	//println("DEBUG getMethod:", tid, path, name)
	if tid < 1 || tid >= len(TypeTable) { // entry 0 is always nil
		hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() type id out of range")
	}
	rt := TypeTable[tid]
	ut := (*uncommonType)(rt.uncommonType)
	if ut == nil {
		hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() type has no uncommonType record")
	}
	if name == "" {
		hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() no method name")
	}
	exported := false
	if name[0] >= 'A' && name[0] <= 'Z' {
		exported = true
		// exported name, so path should be ""
		path = ""
	}
	if path != "" {
		for _, m := range ut.methods { // TODO these should be in order, so could use sort.search to speed up?
			mname := ""
			if m.name != nil {
				mname = *m.name
			}
			mpath := ""
			if m.pkgPath != nil {
				mpath = *m.pkgPath
			}
			//println("DEBUG check:", getTypeString(tid), mname, name, mpath, path)
			if mname == name && mpath == path {
				ret := m.ifn // is ifn the right one?
				if hx.IsNull(ret) {
					hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() null method for "+
						getTypeString(tid)+"."+name+" called from "+path)
				}
				//println("DEBUG found:", getTypeString(tid), path, name, ret)
				return ret
			}
		}
	} else {
		// no path so find the method without the path, but only if it is unique when not exported
		found := -1
		for f, m := range ut.methods { // TODO these should be in order, so could use sort.search to speed up?
			mname := ""
			if m.name != nil {
				mname = *m.name
			}
			//println("DEBUG check (ignore path):", getTypeString(tid), mname, name)
			if mname == name {
				//println("DEBUG found (ignore path):", getTypeString(tid), name)
				if found == -1 {
					found = f
					if exported {
						break
					}
				} else {
					hx.Call("", "Scheduler.panicFromHaxe", 1,
						"haxegoruntime.method() duplicates method found (ignoring path) for "+
							getTypeString(tid)+"."+name+" called from "+path)
				}
			}
		}
		if found >= 0 {
			ret := ut.methods[found].ifn // is ifn the right one?
			if hx.IsNull(ret) {
				hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() null method for "+
					getTypeString(tid)+"."+name+" called from "+path)
			}
			return ret
		}
	}
	//println("DEBUG not found:", getTypeString(tid), path, name)
	hx.Call("", "Scheduler.panicFromHaxe", 1, "haxegoruntime.method() no method found for "+
		getTypeString(tid)+"."+name+" called from "+path)
	return 0
}
コード例 #7
0
ファイル: tgotypes.go プロジェクト: henrylee2cn/tardisgo
func init() {
	hx.Call("", "Tgotypes.setup", 0) // to set-up the TypeTable above
	//typetest()
	//println("DEBUG sizeof(funcType{}) = ", unsafe.Sizeof(funcType{}))
}