Skip to content

Commit

Permalink
Add -Werror to treat warnings as errors
Browse files Browse the repository at this point in the history
Fixes #9.
  • Loading branch information
rillig committed Jul 16, 2024
1 parent 47d164f commit a58808b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkglint.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.\" Thomas Klausner <[email protected]>, 2012.
.\" Roland Illig <[email protected]>, 2015-2020.
.\"
.Dd January 26, 2020
.Dd July 16, 2024
.Dt PKGLINT 1
.Os
.Sh NAME
Expand Down Expand Up @@ -101,6 +101,8 @@ Check inter-package consistency for distfile hashes and used licenses.
Enable all warnings.
.It Cm none
Disable all warnings.
.It Cm [no-]error
Treat warnings as errors; only affects the exit status.
.It Cm [no-]extra
Emit some additional warnings that are not enabled by default.
.It Cm [no-]perm
Expand Down
5 changes: 5 additions & 0 deletions v23/pkglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const confVersion = "@VERSION@"
type Pkglint struct {
CheckGlobal bool

WarnError,
WarnExtra,
WarnPerm,
WarnQuoting bool
Expand Down Expand Up @@ -131,6 +132,9 @@ func (p *Pkglint) Main(stdout io.Writer, stderr io.Writer, args []string) (exitC
p.Pkgsrc.checkToplevelUnusedLicenses()

p.Logger.ShowSummary(args)
if p.WarnError && p.Logger.warnings != 0 {
return 1
}
if p.Logger.errors != 0 {
return 1
}
Expand Down Expand Up @@ -251,6 +255,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.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
47 changes: 47 additions & 0 deletions v23/pkglint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (s *Suite) Test_Pkglint_Main__help(c *check.C) {
" Flags for -W, --warning:",
" all all of the following",
" none none of the following",
" error treat warnings as errors (disabled)",
" extra enable some extra warnings (disabled)",
" perm warn about unforeseen variable definition and use (disabled)",
" quoting warn about quoting issues (disabled)",
Expand Down Expand Up @@ -340,6 +341,52 @@ func (s *Suite) Test_Pkglint_Main__profiling_error(c *check.C) {
`ERROR: pkglint\.pprof: Cannot create profiling file: open pkglint\.pprof: .*`)
}

func (s *Suite) Test_Pkglint_Main__Werror_no_warning(c *check.C) {
t := s.Init(c)

t.SetUpPackage("category/package")
t.Chdir("category/package")

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

t.CheckEquals(exitcode, 0)
t.CheckOutputLines(
"Looks fine.")
}

func (s *Suite) Test_Pkglint_Main__Werror_warning(c *check.C) {
t := s.Init(c)

t.SetUpPackage("category/package",
"UNUSED=\tvalue")
t.Chdir("category/package")

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

t.CheckEquals(exitcode, 1)
t.CheckOutputLines(
"WARN: Makefile:20: UNUSED is defined but not used.",
"1 warning found.",
"(Run \"pkglint -e -Werror\" to show explanations.)")
}

func (s *Suite) Test_Pkglint_Main__Werror_error(c *check.C) {
t := s.Init(c)

t.SetUpPackage("category/package",
"DEPENDS+=\tother>=0:../../category/does-not-exist")
t.Chdir("category/package")

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

t.CheckEquals(exitcode, 1)
t.CheckOutputLines(
"ERROR: Makefile:20: Relative path "+
"\"../../category/does-not-exist/Makefile\" "+
"does not exist.",
"1 error found.")
}

// Branch coverage for Logger.Logf, the level != Fatal case.
func (s *Suite) Test_Pkglint_prepareMainLoop__fatal(c *check.C) {
t := s.Init(c)
Expand Down

0 comments on commit a58808b

Please sign in to comment.