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

.

parent f67bb046
package main package main
import ( import (
"bytes"
"go/build" "go/build"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"syscall"
"testing" "testing"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
...@@ -63,13 +66,15 @@ func prepareTestTree(src, dst string, mode TreePrepareMode) error { ...@@ -63,13 +66,15 @@ func prepareTestTree(src, dst string, mode TreePrepareMode) error {
switch mode { switch mode {
case TreePrepareGolden: case TreePrepareGolden:
// no removed files in golden tree // ok files are written as is
// no removed files
if isRm { if isRm {
return nil return nil
} }
case TreePrepareWork: case TreePrepareWork:
// no ok files initially in work tree // no ok files initially
if isOk { if isOk {
return nil return nil
} }
...@@ -93,6 +98,20 @@ func xprepareTree(src, dst string, mode TreePrepareMode) { ...@@ -93,6 +98,20 @@ func xprepareTree(src, dst string, mode TreePrepareMode) {
exc.Raiseif(err) 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) { func TestGoTraceGen(t *testing.T) {
tmp, err := ioutil.TempDir("", "t-gotrace") tmp, err := ioutil.TempDir("", "t-gotrace")
if err != nil { if err != nil {
...@@ -124,9 +143,13 @@ func TestGoTraceGen(t *testing.T) { ...@@ -124,9 +143,13 @@ func TestGoTraceGen(t *testing.T) {
t.Errorf("%v: %v", tpkg, err) t.Errorf("%v: %v", tpkg, err)
} }
err := diffR(good+"/"+tpkg, work+"/"+tpkg) diff, err := diffR(good+"/"+tpkg, work+"/"+tpkg)
if err != nil { 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