From 5d3b2980af9587dd78123bdae08c1f8322c3ee08 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sat, 31 Aug 2024 09:26:22 +0200 Subject: [PATCH] Don't imply -Werror on -Wall Since 23.5.0. --- v23/getopt/getopt.go | 15 +++++++++++++-- v23/getopt/getopt_test.go | 15 +++++++++++++++ v23/pkglint.go | 2 +- v23/pkglint_test.go | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/v23/getopt/getopt.go b/v23/getopt/getopt.go index 6378410c..5632a586 100644 --- a/v23/getopt/getopt.go +++ b/v23/getopt/getopt.go @@ -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 } @@ -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 } diff --git a/v23/getopt/getopt_test.go b/v23/getopt/getopt_test.go index f1f06cde..80caa7b4 100644 --- a/v23/getopt/getopt_test.go +++ b/v23/getopt/getopt_test.go @@ -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) diff --git a/v23/pkglint.go b/v23/pkglint.go index 0219f2d7..b77434d3 100644 --- a/v23/pkglint.go +++ b/v23/pkglint.go @@ -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") diff --git a/v23/pkglint_test.go b/v23/pkglint_test.go index 694a38c2..b1433c4d 100644 --- a/v23/pkglint_test.go +++ b/v23/pkglint_test.go @@ -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.",