Created
November 30, 2015 14:24
-
-
Save keegancsmith/677d554e79b4018f129c to your computer and use it in GitHub Desktop.
Scripts to ensure no regressions in srclib-go go1.5.1 toolchain upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
"path/filepath" | |
"reflect" | |
"strings" | |
) | |
func newImportPath(s string) string { | |
return strings.Replace(s, "sourcegraph.com/sourcegraph/srclib-go/testdata/case", "github.com/sgtest", 1) | |
} | |
func readJSON(path string) (interface{}, error) { | |
b, err := ioutil.ReadFile(path) | |
if err != nil { | |
return nil, err | |
} | |
var x interface{} | |
err = json.Unmarshal(b, &x) | |
return x, err | |
} | |
func main() { | |
walk := func(path string, info os.FileInfo, err error) error { | |
if info.IsDir() { | |
return nil | |
} | |
actualPath := strings.Replace(path, "/expected/", "/actual/", 1) | |
actual, err := readJSON(actualPath) | |
if err != nil { | |
return err | |
} | |
expected, err := readJSON(path) | |
if err != nil { | |
return err | |
} | |
if !reflect.DeepEqual(expected, actual) { | |
return fmt.Errorf("%s != %s", path, actualPath) | |
} | |
return nil | |
} | |
err := filepath.Walk("testdata/expected/program", walk) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
"os" | |
"os/exec" | |
"path/filepath" | |
"strings" | |
) | |
func newImportPath(s string) string { | |
s = strings.Replace(s, "sourcegraph.com/sourcegraph/srclib-go/testdata/case", "github.com/sgtest", 1) | |
if s == "go1.4.2" { | |
s = "go1.5.1" | |
} | |
return s | |
} | |
func update(x interface{}) interface{} { | |
if s, ok := x.(string); ok { | |
return newImportPath(s) | |
} | |
if m, ok := x.(map[string]interface{}); ok { | |
for k, v := range m { | |
m[k] = update(v) | |
} | |
if _, exists := m["PkgRoot"]; exists { | |
m["PkgTargetRoot"] = "" | |
} | |
return m | |
} | |
if a, ok := x.([]interface{}); ok { | |
for i := range a { | |
a[i] = update(a[i]) | |
} | |
return a | |
} | |
return x | |
} | |
func main() { | |
walk := func(path string, info os.FileInfo, err error) error { | |
if info.IsDir() { | |
return nil | |
} | |
dest := newImportPath(path) | |
if path != dest { | |
log.Printf("%s -> %s", path, dest) | |
os.MkdirAll(filepath.Dir(dest), 0770) | |
out, err := exec.Command("git", "mv", path, dest).CombinedOutput() | |
if err != nil { | |
log.Fatal(string(out)) | |
return err | |
} | |
} | |
if strings.HasSuffix(dest, ".json") { | |
b, err := ioutil.ReadFile(dest) | |
if err != nil { | |
return err | |
} | |
var x interface{} | |
err = json.Unmarshal(b, &x) | |
if err != nil { | |
return err | |
} | |
x = update(x) | |
b2, err := json.Marshal(x) | |
if err != nil { | |
return err | |
} | |
b2 = append(b2, '\n') | |
if string(b) != string(b2) { | |
log.Printf("Updating %s", dest) | |
err = ioutil.WriteFile(dest, b2, 0660) | |
if err != nil { | |
return err | |
} | |
} | |
} | |
return nil | |
} | |
err := filepath.Walk("testdata/expected/program", walk) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment