Exemplo n.º 1
0
func gocov_update(ir *gothic.Interpreter) {
	ir.Eval(`
		.f2.funcs delete [.f2.funcs children {}]
	`)
	ir.EvalAs(&xsourceview, ".f1.sourceview xview")
	ir.EvalAs(&ysourceview, ".f1.sourceview yview")
	gocov_test(ir)
}
Exemplo n.º 2
0
func gocov_test(ir *gothic.Interpreter) {
	var buf bytes.Buffer
	cmd := exec.Command("gocov", "test")
	cmd.Stdout = &buf
	err := cmd.Run()
	if err != nil {
		gocov_test_error(ir, err)
		return
	}

	result := struct{ Packages []*gocov.Package }{}
	err = json.Unmarshal(buf.Bytes(), &result)
	if err != nil {
		gocov_test_error(ir, err)
		return
	}

	sel := ""
	current = result.Packages
	for pi, p := range result.Packages {
		for fi, f := range p.Functions {
			r := reached(f)
			n := len(f.Statements)
			fun := fmt.Sprintf("%s.%s", p.Name, f.Name)
			cov := fmt.Sprintf("%.2f%% (%d/%d)", percentage(r, n), r, n)
			file := fmt.Sprintf("%s/%s", p.Name, filepath.Base(f.File))
			id := fmt.Sprintf("f_%d_%d", pi, fi)
			if prevsel != "" && prevsel == fun {
				sel = id
			}
			ir.Eval(`.f2.funcs insert {} end -id `, id,
				` -values {`, strconv.Quote(fun),
				` `, strconv.Quote(file),
				` `, strconv.Quote(cov), `}`)
		}
	}

	dir := filepath.Dir(current[0].Functions[0].File)
	ir.Set("pathtext", dir)

	done := 0
	total := 0
	for _, p := range result.Packages {
		for _, f := range p.Functions {
			done += reached(f)
			total += len(f.Statements)
		}
	}
	ir.Set("covtext", fmt.Sprintf("Overall coverage: %.2f%% (%d/%d)",
		percentage(done, total), done, total))

	if sel == "" {
		sel = "f_0_0"
	}
	ir.Eval(".f2.funcs selection set ", sel)
}
Exemplo n.º 3
0
func gocov_selection(ir *gothic.Interpreter) {
	var selection string
	ir.EvalAs(&selection, ".f2.funcs selection")

	var pi, fi int
	_, err := fmt.Sscanf(selection, "f_%d_%d", &pi, &fi)
	if err != nil {
		panic(err)
	}

	f := current[pi].Functions[fi]
	prevsel = fmt.Sprintf("%s.%s", current[pi].Name, f.Name)

	data, err := ioutil.ReadFile(f.File)
	if err != nil {
		panic(err)
	}

	ir.Set("source", string(data[f.Start:f.End]))
	ir.Eval(`
		.f1.sourceview configure -state normal
		.f1.sourceview delete 1.0 end
		.f1.sourceview insert end $source
		.f1.sourceview configure -state disabled
	`)
	for _, s := range f.Statements {
		if s.Reached != 0 {
			continue
		}
		ls, le := s.Start-f.Start, s.End-f.Start
		ir.Eval(`.f1.sourceview tag add red {1.0 +`, ls, `chars} {1.0 +`, le, `chars}`)
	}

	if xsourceview != "" {
		ir.Eval(".f1.sourceview xview moveto [lindex {", xsourceview, "} 0]")
		ir.Eval(".f1.sourceview yview moveto [lindex {", ysourceview, "} 0]")
		xsourceview = ""
		ysourceview = ""
	}
}
Exemplo n.º 4
0
func applyOp(op string, ir *gothic.Interpreter) {
	var num string
	ir.EvalAs(&num, "set calcText")
	if args[0] == nil {
		if op != "=" {
			args[0] = big.NewInt(0)
			args[0].SetString(num, 10)
		}
	} else {
		args[1] = big.NewInt(0)
		args[1].SetString(num, 10)
	}

	afterOp = true

	if args[1] == nil {
		lastOp = op
		return
	}

	switch lastOp {
	case "+":
		args[0] = args[0].Add(args[0], args[1])
	case "-":
		args[0] = args[0].Sub(args[0], args[1])
	case "/":
		args[0] = args[0].Div(args[0], args[1])
	case "*":
		args[0] = args[0].Mul(args[0], args[1])
	}

	lastOp = op
	args[1] = nil

	ir.Eval("set calcText ", args[0])
	if op == "=" {
		args[0] = nil
	}
}
Exemplo n.º 5
0
func proc(ir *gothic.Interpreter, num string) {
	button := ".b" + num
	progress := ".p" + num
	channame := "proc" + num
	recv := make(chan int)

	// register channel and enable button
	ir.RegisterCommand(channame, func(_ string, arg int) {
		recv <- arg
	})
	ir.Eval(`%{} configure -state normal`, button)

	for {
		// wait for an event
		<-recv

		// simulate activity
		ir.Eval(`%{} configure -state disabled -text "In Progress %{}"`, button, num)
		for i := 0; i <= 100; i += 2 {
			ir.Eval(`%{%s} configure -value %{}`, progress, i)
			time.Sleep(5e7)
		}

		// reset button state and progress value
		ir.Eval(`%{} configure -value 0`, progress)
		ir.Eval(`%{} configure -state normal -text "Start %{}"`, button, num)
	}
}
Exemplo n.º 6
0
func gocov_test_error(ir *gothic.Interpreter, err error) {
	ir.Eval(`tk_messageBox -title "gocov test error" -icon error -message `,
		strconv.Quote(err.Error()))
}
Exemplo n.º 7
0
func initGUI(ir *gothic.Interpreter) {
	ir.UploadImage("bg", loadPNG("background.png"))
	ir.Eval(`ttk::label .l -image bg`)
	ir.Eval(`pack .l -expand true`)
}