Esempio n. 1
0
File: out.go Progetto: 8l/leaf
func testOut(t *testing.T, src []byte, out []byte) {
	run := new(script.Run)
	run.Filename = "test.l"
	run.Source = src
	run.Run()

	if len(run.Errors) > 0 {
		for _, e := range run.Errors {
			t.Error(e)
		}
	}

	if !run.RIP() {
		t.Errorf("vm exit with half value %d", run.HaltValue)
		if run.AddrError {
			t.Errorf("vm has address error")
		}
	}

	if !match(out, run.Output) {
		t.Errorf("output does not match")
		t.Logf("  expect: %q", out)
		t.Logf("  got: %q", run.Output)
	}
}
Esempio n. 2
0
File: run.go Progetto: 8l/leaf
func mainRun(args []string) {

	if len(args) != 1 {
		printError(fmt.Errorf("need one argument to run"))
		os.Exit(1)
	}

	src, e := ioutil.ReadFile(args[0])
	if e != nil {
		printError(e)
		os.Exit(1)
	}

	run := new(script.Run)
	run.Filename = args[0]
	run.Source = src
	run.Stdout = os.Stdout
	run.Run()

	if len(run.Errors) > 0 {
		printErrors(run.Errors)
		os.Exit(1)
	}

	if !run.RIP() {
		fmt.Printf("(ret=%d)\n", run.HaltValue)
		if run.AddrError {
			printError(fmt.Errorf("vm halted on address error"))
		}
	}

	fmt.Printf("(%d cycles)\n", run.UsedCycle)
}