Skip to content

Commit

Permalink
Merge pull request #145 from grafana/clean-test-corpus
Browse files Browse the repository at this point in the history
thema: Clean up txtar corpus outputs
  • Loading branch information
sam boyer committed May 11, 2023
2 parents 9a5baae + 9d92f91 commit a47c724
Show file tree
Hide file tree
Showing 25 changed files with 1,671 additions and 1,764 deletions.
51 changes: 51 additions & 0 deletions magefile.go
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
}
7 changes: 0 additions & 7 deletions testdata/invalidlineage/defaultchange.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ lenses: [
}
},
]
-- out/bindfail --
not a lineage, missing #Lineage.name
(1) forced error mark
| "not a lineage"
| github.com/cockroachdb/errors/withstack/*withstack.withStack::
Wraps: (2) not a lineage, missing #Lineage.name
Error types: (1) *markers.withMark (2) *errors.errorString
8 changes: 0 additions & 8 deletions testdata/invalidlineage/onlydef.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@ schemas: [{
}
}]
lenses: []
-- out/bindfail --
_sortedSchemas: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
../../lineage.cue:97:7
../../lineage.cue:93:21
../../lineage.cue:97:21
schemas.0._schemaIsNonEmpty: invalid value {#Baz:{run:string,tell:bytes,dat:int & >=-2147483648 & <=2147483647}} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
../../lineage.cue:259:21
../../lineage.cue:259:38
Loading

0 comments on commit a47c724

Please sign in to comment.