|
| 1 | +# Tests Issue #10500 |
| 2 | + |
| 3 | +[!race] skip |
| 4 | + |
| 5 | +env GOBIN=$WORK/bin |
| 6 | +go install mtime sametime |
| 7 | + |
| 8 | +go tool -n cgo |
| 9 | +cp stdout cgopath.txt |
| 10 | +exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt |
| 11 | +cp stdout cgotime_before.txt |
| 12 | + |
| 13 | + # For this test, we don't actually care whether 'go test -race -i' succeeds. |
| 14 | + # It may fail, for example, if GOROOT was installed from source as root and |
| 15 | + # is now read-only. |
| 16 | + # We only care that — regardless of whether it succeeds — it does not |
| 17 | + # overwrite cmd/cgo. |
| 18 | +go test -race -i runtime/race |
| 19 | + |
| 20 | +exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt |
| 21 | +cp stdout cgotime_after.txt |
| 22 | +exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt |
| 23 | + |
| 24 | +-- mtime/mtime.go -- |
| 25 | +package main |
| 26 | + |
| 27 | +import ( |
| 28 | + "io/ioutil" |
| 29 | + "encoding/json" |
| 30 | + "fmt" |
| 31 | + "os" |
| 32 | + "strings" |
| 33 | +) |
| 34 | + |
| 35 | +func main() { |
| 36 | + b, err := ioutil.ReadFile(os.Args[1]) |
| 37 | + if err != nil { |
| 38 | + fmt.Fprintln(os.Stderr, err) |
| 39 | + os.Exit(1) |
| 40 | + } |
| 41 | + filename := strings.TrimSpace(string(b)) |
| 42 | + info, err := os.Stat(filename) |
| 43 | + if err != nil { |
| 44 | + fmt.Fprintln(os.Stderr, err) |
| 45 | + os.Exit(1) |
| 46 | + } |
| 47 | + if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil { |
| 48 | + fmt.Fprintln(os.Stderr, err) |
| 49 | + os.Exit(1) |
| 50 | + } |
| 51 | +} |
| 52 | +-- sametime/sametime.go -- |
| 53 | +package main |
| 54 | + |
| 55 | +import ( |
| 56 | + "encoding/json" |
| 57 | + "fmt" |
| 58 | + "io/ioutil" |
| 59 | + "os" |
| 60 | + "time" |
| 61 | +) |
| 62 | + |
| 63 | + |
| 64 | +func main() { |
| 65 | + var t1 time.Time |
| 66 | + b1, err := ioutil.ReadFile(os.Args[1]) |
| 67 | + if err != nil { |
| 68 | + fmt.Fprintln(os.Stderr, err) |
| 69 | + os.Exit(1) |
| 70 | + } |
| 71 | + if err := json.Unmarshal(b1, &t1); err != nil { |
| 72 | + fmt.Fprintln(os.Stderr, err) |
| 73 | + os.Exit(1) |
| 74 | + } |
| 75 | + |
| 76 | + var t2 time.Time |
| 77 | + b2, err := ioutil.ReadFile(os.Args[2]) |
| 78 | + if err != nil { |
| 79 | + fmt.Fprintln(os.Stderr, err) |
| 80 | + os.Exit(1) |
| 81 | + } |
| 82 | + if err := json.Unmarshal(b2, &t2); err != nil { |
| 83 | + fmt.Fprintln(os.Stderr, err) |
| 84 | + os.Exit(1) |
| 85 | + } |
| 86 | + |
| 87 | + if !t1.Equal(t2) { |
| 88 | + fmt.Fprintf(os.Stderr, "time in %v (%v) is not the same as time in %v (%v)", os.Args[1], t1, os.Args[2], t2) |
| 89 | + os.Exit(1) |
| 90 | + } |
| 91 | +} |
0 commit comments