Skip to content

Commit

Permalink
Don't imply -Werror on -Wall
Browse files Browse the repository at this point in the history
Since 23.5.0.
  • Loading branch information
rillig committed Aug 31, 2024
1 parent 7dcf96d commit 5d3b298
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
15 changes: 13 additions & 2 deletions v23/getopt/getopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,19 @@ type groupFlag struct {
name string
value *bool
description string
all bool
}

func (fg *FlagGroup) AddFlagVar(name string, flag *bool, defval bool, description string) {
opt := groupFlag{name, flag, description}
opt := groupFlag{name, flag, description, true}
fg.flags = append(fg.flags, &opt)
*flag = defval
}

// AddFlagVarNoAll adds a flag to the group that is not affected by the "all"
// or "none" options.
func (fg *FlagGroup) AddFlagVarNoAll(name string, flag *bool, defval bool, description string) {
opt := groupFlag{name, flag, description, false}
fg.flags = append(fg.flags, &opt)
*flag = defval
}
Expand All @@ -372,7 +381,9 @@ func (fg *FlagGroup) parseOpt(optionPrefix, argOpt string) error {

if argOpt == "none" || argOpt == "all" {
for _, opt := range fg.flags {
*opt.value = argOpt == "all"
if opt.all {
*opt.value = argOpt == "all"
}
}
return nil
}
Expand Down
15 changes: 15 additions & 0 deletions v23/getopt/getopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ func (s *Suite) Test_Options_Help__partial(c *check.C) {
" --long Only long option\n")
}

func (s *Suite) Test_FlagGroup_AddFlagVarNoAll(c *check.C) {
opts := NewOptions()

var warnCommon, warnError bool
group := opts.AddFlagGroup('W', "warn", "warnings", "descr")
group.AddFlagVar("common", &warnCommon, false, "Enable common warnings")
group.AddFlagVarNoAll("error", &warnError, false, "Treat warnings as errors")

args, err := opts.Parse([]string{"program", "-Wall"})
c.Check(err, check.IsNil)
c.Check(args, check.IsNil)
c.Check(warnCommon, check.Equals, true)
c.Check(warnError, check.Equals, false)
}

func (s *Suite) Test__qa(c *check.C) {
ck := intqa.NewQAChecker(c.Errorf)
ck.Configure("*", "*", "*", -intqa.EMissingTest)
Expand Down
2 changes: 1 addition & 1 deletion v23/pkglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (p *Pkglint) ParseCommandLine(args []string) int {

check.AddFlagVar("global", &p.CheckGlobal, false, "inter-package checks")

warn.AddFlagVar("error", &p.WarnError, false, "treat warnings as errors")
warn.AddFlagVarNoAll("error", &p.WarnError, false, "treat warnings as errors")
warn.AddFlagVar("extra", &p.WarnExtra, false, "enable some extra warnings")
warn.AddFlagVar("perm", &p.WarnPerm, false, "warn about unforeseen variable definition and use")
warn.AddFlagVar("quoting", &p.WarnQuoting, false, "warn about quoting issues")
Expand Down
2 changes: 1 addition & 1 deletion v23/pkglint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (s *Suite) Test_Pkglint_Main__Wall(c *check.C) {

exitcode := t.Main("-Wall")

t.CheckEquals(exitcode, 1) // FIXME
t.CheckEquals(exitcode, 0)
t.CheckOutputLines(
"WARN: Makefile:20: UNUSED is defined but not used.",
"1 warning found.",
Expand Down

0 comments on commit 5d3b298

Please sign in to comment.