Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -321,7 +320,9 @@ func addBuildTag(src []byte, tag string) []byte {
}

// printDiff prints a unified diff between orig and rewritten for path,
// using the system diff command.
// using the system diff command. Both sides are labeled with path, so the
// header does not depend on the temporary files or on which diff is installed
// (GNU and BSD diff print their timestamps differently).
func printDiff(path string, orig, rewritten []byte) error {
origFile, err := os.CreateTemp("", "loopvec-orig-*.go")
if err != nil {
Expand All @@ -345,9 +346,7 @@ func printDiff(path string, orig, rewritten []byte) error {
}
_ = newFile.Close()

out, _ := exec.Command("diff", "-u", origFile.Name(), newFile.Name()).Output()
out = bytes.ReplaceAll(out, []byte(origFile.Name()), []byte(path))
out = bytes.ReplaceAll(out, []byte(newFile.Name()), []byte(path))
out, _ := exec.Command("diff", "-u", "-L", path, "-L", path, origFile.Name(), newFile.Name()).Output()
_, err = os.Stdout.Write(out)
return err
}
8 changes: 4 additions & 4 deletions testdata/flag_diff.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -d prints a unified diff (paths in the headers, timestamps aside) and leaves
# the source untouched.
# -d prints a unified diff, labeled with the file's path on both sides so the
# headers are the same with GNU and BSD diff, and leaves the source untouched.

cp ops.go ops.go.orig
loopvec -d .
cmpenv stderr stderr.want
stdout -count=1 '^--- \S+/ops\.go\t\S+ \S+ [+-][0-9]{4}$'
stdout -count=1 '^\+\+\+ \S+/ops\.go\t\S+ \S+ [+-][0-9]{4}$'
stdout -count=1 '^--- \S+/ops\.go$'
stdout -count=1 '^\+\+\+ \S+/ops\.go$'
stdout -count=1 '^@@ -1,7 \+1,43 @@$'
stdout -count=1 '^\+//go:build goexperiment.simd$'
stdout -count=1 '^\+import \($'
Expand Down
2 changes: 1 addition & 1 deletion testdata/readme_go_tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go work use $LOOPVEC_SRC

exec go tool loopvec -d ./...
cmpenv stderr stderr.want
stdout -count=1 '^\+\+\+ \S+/mypkg/ops\.go\t'
stdout -count=1 '^\+\+\+ \S+/mypkg/ops\.go$'

exec go tool loopvec -split ./mypkg/...
! stdout .
Expand Down
8 changes: 4 additions & 4 deletions testdata/readme_patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ cmp b/ops.go b/ops.go.orig

# unified diff, once per changed file
loopvec -d ./...
stdout -count=1 '^--- \S+/a/ops\.go\t'
stdout -count=1 '^\+\+\+ \S+/a/ops\.go\t'
stdout -count=1 '^--- \S+/b/ops\.go\t'
stdout -count=1 '^\+\+\+ \S+/b/ops\.go\t'
stdout -count=1 '^--- \S+/a/ops\.go$'
stdout -count=1 '^\+\+\+ \S+/a/ops\.go$'
stdout -count=1 '^--- \S+/b/ops\.go$'
stdout -count=1 '^\+\+\+ \S+/b/ops\.go$'
stdout -count=2 '^@@ -1,7 \+1,43 @@$'
cmpenv stderr both.stderr
cmp a/ops.go a/ops.go.orig
Expand Down
2 changes: 1 addition & 1 deletion testdata/readme_workflow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 1. Preview changes
loopvec -d ./mypkg/...
cmpenv stderr stderr.want
stdout -count=1 '^\+\+\+ \S+/mypkg/ops\.go\t'
stdout -count=1 '^\+\+\+ \S+/mypkg/ops\.go$'
! exists mypkg/ops_simd.go

# 2. Apply: creates ops_simd.go and guards ops.go
Expand Down