mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(confusion-matrix): name every missing required flag, in flag order
This commit is contained in:
1 parent
627f9eeeff
commit
badabbaed8
2 files changed
+41
-7
No files matched your search
@@ -54,16 +54,25 @@ func run(arguments []string, stdout, stderr io.Writer) error {
|
|||||||
if err := flagSet.Parse(arguments); err != nil {
|
if err := flagSet.Parse(arguments); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for name, value := range map[string]string{
|
// Every missing flag is named together, in flag order: stopping at the
|
||||||
"--sweep": sweepDirectory,
|
// first turns one rerun into one rerun per missing flag.
|
||||||
"--reviews": reviewsDirectory,
|
var missing []error
|
||||||
"--assignment": assignmentPath,
|
for _, required := range []struct {
|
||||||
"--property-clauses": mappingPath,
|
name string
|
||||||
|
value string
|
||||||
|
}{
|
||||||
|
{"--sweep", sweepDirectory},
|
||||||
|
{"--reviews", reviewsDirectory},
|
||||||
|
{"--assignment", assignmentPath},
|
||||||
|
{"--property-clauses", mappingPath},
|
||||||
} {
|
} {
|
||||||
if value == "" {
|
if required.value == "" {
|
||||||
return fmt.Errorf("%s is required", name)
|
missing = append(missing, fmt.Errorf("%s is required", required.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := errors.Join(missing...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
mapping, err := loadMapping(mappingPath)
|
mapping, err := loadMapping(mappingPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -31,6 +31,31 @@ func scoredFixture(name, model string) fixtureImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Three flags missing is one rerun, not three: the operator is told about all
|
||||||
|
// of them at once, in flag order, whatever order the check happened to walk.
|
||||||
|
func TestRunNamesEveryMissingRequiredFlagInFlagOrder(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := run([]string{"--sweep", "s"}, &stdout, &stderr)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("got no error, want every missing flag named")
|
||||||
|
}
|
||||||
|
message := err.Error()
|
||||||
|
previous := -1
|
||||||
|
for _, name := range []string{"--reviews", "--assignment", "--property-clauses"} {
|
||||||
|
at := strings.Index(message, name)
|
||||||
|
if at < 0 {
|
||||||
|
t.Fatalf("got %q, want %s named", message, name)
|
||||||
|
}
|
||||||
|
if at < previous {
|
||||||
|
t.Errorf("got %q, want the flags named in flag order", message)
|
||||||
|
}
|
||||||
|
previous = at
|
||||||
|
}
|
||||||
|
if strings.Contains(message, "--sweep") {
|
||||||
|
t.Errorf("got %q, want the supplied --sweep left out", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMappingRefusesInputTheMatrixCannotBeScoredFrom(t *testing.T) {
|
func TestMappingRefusesInputTheMatrixCannotBeScoredFrom(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in new issue
Block a user