Skip to content

Commit

Permalink
Merge branch 'main' into feature/all_or_nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
sho-hata committed Oct 30, 2024
2 parents 3cada05 + 1aec06d commit b0ebb7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/tparagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
kingpin.HelpFlag.Short('h')

if err := tparagen.Run(os.Stdout, os.Stderr, strings.Split(*ignoreDirectories, ","), *minGoVersion); err != nil {
os.Stderr.WriteString(err.Error())
fmt.Println(err.Error())
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
testPrefix = "Test"
)

func GenerateTParallel(filename string, src []byte, needFixLoopVar bool) ([]byte, error) {
func Process(filename string, src []byte, needFixLoopVar bool) ([]byte, error) {
fs := token.NewFileSet()

f, err := parser.ParseFile(fs, filename, src, parser.ParseComments)
Expand Down
2 changes: 1 addition & 1 deletion process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ func TestFunctionRangeMissingCallToParallel(t *testing.T) {
t.Run(tt.testCase, func(t *testing.T) {
t.Parallel()

got, err := GenerateTParallel("./testdata/t/t_test.go", []byte(tt.src), tt.needFixLoopVar)
got, err := Process("./testdata/t/t_test.go", []byte(tt.src), tt.needFixLoopVar)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
18 changes: 12 additions & 6 deletions tparagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Run(outStream, errStream io.Writer, ignoreDirectories []string, minGoVersio

t := &tparagen{
in: defaultTargetDir,
dest: "",
outStream: outStream,
errStream: errStream,
ignoreDirs: ignoreDirs,
Expand All @@ -41,15 +42,12 @@ func Run(outStream, errStream io.Writer, ignoreDirectories []string, minGoVersio
}

type tparagen struct {
in string
in, dest string
outStream, errStream io.Writer
ignoreDirs []string
needFixLoopVar bool
}

// run() traverses from the root node, and when it finds the target test file, it will process the assignment of a concurrency marker.
// The contents of each processed file are written to a temporary file.
// After all scans are complete, rewrite the original file with the contents of each temporary file.
func (t *tparagen) run() error {
// Information of files to be modified
// key: original file path, value: temporary file path
Expand All @@ -76,7 +74,15 @@ func (t *tparagen) run() error {
return filepath.SkipDir
}

if info.IsDir() || filepath.Ext(path) != ".go" || !strings.HasSuffix(filepath.Base(path), "_test.go") {
if info.IsDir() {
return nil
}

if filepath.Ext(path) != ".go" {
return nil
}

if !strings.HasSuffix(filepath.Base(path), "_test.go") {
return nil
}

Expand All @@ -98,7 +104,7 @@ func (t *tparagen) run() error {
return fmt.Errorf("cannot read %s. %w", path, err)
}

got, err := GenerateTParallel(path, b, t.needFixLoopVar)
got, err := Process(path, b, t.needFixLoopVar)
if err != nil {
return fmt.Errorf("error occurred in Process(). %w", err)
}
Expand Down

0 comments on commit b0ebb7f

Please sign in to comment.