-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from grafana/clean-test-corpus
thema: Clean up txtar corpus outputs
- Loading branch information
Showing
25 changed files
with
1,671 additions
and
1,764 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build mage | ||
|
||
package main | ||
|
||
import ( | ||
"golang.org/x/tools/txtar" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// Clean cleans all the output from corpus txtar files | ||
func Clean() error { | ||
return filepath.Walk("./testdata", cleanTxtarOut) | ||
} | ||
|
||
func cleanTxtarOut(path string, _ os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if filepath.Ext(path) != ".txtar" { | ||
return nil | ||
} | ||
|
||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
archive := txtar.Parse(data) | ||
archive.Files = filter( | ||
archive.Files, | ||
func(t txtar.File) bool { | ||
return !strings.HasPrefix(t.Name, "out") | ||
}, | ||
) | ||
|
||
return os.WriteFile(path, txtar.Format(archive), 0666) | ||
|
||
} | ||
|
||
func filter(ff []txtar.File, criteria func(f txtar.File) bool) []txtar.File { | ||
filtered := make([]txtar.File, 0, len(ff)) | ||
for _, f := range ff { | ||
if criteria(f) { | ||
filtered = append(filtered, f) | ||
} | ||
} | ||
return filtered | ||
} |
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
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
Oops, something went wrong.