Commit 085049f6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f67bb046
package main
import (
"bytes"
"go/build"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"
"testing"
"lab.nexedi.com/kirr/go123/exc"
......@@ -63,13 +66,15 @@ func prepareTestTree(src, dst string, mode TreePrepareMode) error {
switch mode {
case TreePrepareGolden:
// no removed files in golden tree
// ok files are written as is
// no removed files
if isRm {
return nil
}
case TreePrepareWork:
// no ok files initially in work tree
// no ok files initially
if isOk {
return nil
}
......@@ -93,6 +98,20 @@ func xprepareTree(src, dst string, mode TreePrepareMode) {
exc.Raiseif(err)
}
// diffR compares two directories recursively
func diffR(patha, pathb string) (diff string, err error) {
out := &bytes.Buffer{}
cmd := exec.Command("diff", "-urN", patha, pathb)
cmd.Stdout = out
err = cmd.Run()
if e, ok := err.(*exec.ExitError); ok && e.Sys().(syscall.WaitStatus).ExitStatus() == 1 {
err = nil // diff signals with 1 just a difference - problem exit code is 2
}
return out.String(), err
}
func TestGoTraceGen(t *testing.T) {
tmp, err := ioutil.TempDir("", "t-gotrace")
if err != nil {
......@@ -124,9 +143,13 @@ func TestGoTraceGen(t *testing.T) {
t.Errorf("%v: %v", tpkg, err)
}
err := diffR(good+"/"+tpkg, work+"/"+tpkg)
diff, err := diffR(good+"/"+tpkg, work+"/"+tpkg)
if err != nil {
t.Errorf("%v: %v", tpkg, err)
t.Fatalf("%v: %v", tpkg, err)
}
if diff != "" {
t.Errorf("%v: gold & work differ:\n%s", tpkg, diff)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment