Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/pkgsrc/pkgtools/pkglint/files/Attic/redundantscope_test.go,v rcsdiff: /ftp/cvs/cvsroot/pkgsrc/pkgtools/pkglint/files/Attic/redundantscope_test.go,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.7 retrieving revision 1.11 diff -u -p -r1.7 -r1.11 --- pkgsrc/pkgtools/pkglint/files/Attic/redundantscope_test.go 2019/11/17 01:26:25 1.7 +++ pkgsrc/pkgtools/pkglint/files/Attic/redundantscope_test.go 2019/12/13 01:39:23 1.11 @@ -25,7 +25,7 @@ func (s *Suite) Test_RedundantScope__sin t.CheckOutputLines( "NOTE: file.mk:7: Default assignment of VAR.def has no effect because of line 1.", "NOTE: file.mk:8: Definition of VAR.asg is redundant because of line 2.", - "WARN: file.mk:4: Variable VAR.evl is overwritten in line 10.") + "NOTE: file.mk:10: Definition of VAR.evl is redundant because of line 4.") // TODO: "VAR.shl: is overwritten later" } @@ -52,7 +52,7 @@ func (s *Suite) Test_RedundantScope__sin t.CheckOutputLines( "NOTE: file.mk:7: Default assignment of VAR.def has no effect because of line 1.", "NOTE: file.mk:8: Definition of VAR.asg is redundant because of line 2.", - "WARN: file.mk:4: Variable VAR.evl is overwritten in line 10.") + "NOTE: file.mk:10: Definition of VAR.evl is redundant because of line 4.") // TODO: "VAR.shl: is overwritten later" } @@ -107,7 +107,7 @@ func (s *Suite) Test_RedundantScope__sin t.CheckOutputLines( "NOTE: file.mk:7: Default assignment of VAR.def has no effect because of line 1.", "NOTE: file.mk:8: Definition of VAR.asg is redundant because of line 2.", - "WARN: file.mk:4: Variable VAR.evl is overwritten in line 10.") + "NOTE: file.mk:10: Definition of VAR.evl is redundant because of line 4.") // TODO: "VAR.shl: is overwritten later" } @@ -840,7 +840,7 @@ func (s *Suite) Test_RedundantScope__bra t.CheckOutputEmpty() } -// FIXME: Continue the systematic redundancy tests. +// TODO: Continue the systematic redundancy tests. // // Tests where the variables are defined in a .for loop that might not be // evaluated at all. @@ -1246,7 +1246,7 @@ func (s *Suite) Test_RedundantScope__inc "CONFIGURE_ARGS= two", "CONFIGURE_ARGS+= three") t.SetUpPackage("category/dependency") - t.CreateFileDummyBuildlink3("category/dependency/buildlink3.mk") + t.CreateFileBuildlink3("category/dependency/buildlink3.mk") t.CreateFileLines("category/dependency/builtin.mk", MkCvsID, "CONFIGURE_ARGS.Darwin+= darwin") @@ -1332,7 +1332,7 @@ func (s *Suite) Test_RedundantScope__eva NewRedundantScope().Check(mklines) t.CheckOutputLines( - "WARN: filename.mk:1: Variable VAR is overwritten in line 2.", + "NOTE: filename.mk:2: Definition of VAR is redundant because of line 1.", "WARN: filename.mk:2: Variable VAR is overwritten in line 3.") } @@ -1427,6 +1427,48 @@ func (s *Suite) Test_RedundantScope__pro t.CheckOutputEmpty() } +func (s *Suite) Test_RedundantScope__infra(c *check.C) { + t := s.Init(c) + + t.CreateFileLines("mk/bsd.options.mk", + "PKG_OPTIONS:=\t# empty", + "PKG_OPTIONS=\t# empty") + t.CreateFileLines("options.mk", + "OUTSIDE:=\t# empty", + "OUTSIDE=\t# empty", + ".include \"mk/bsd.options.mk\"") + + test := func(diagnostics ...string) { + mklines := t.LoadMkInclude("options.mk") + scope := NewRedundantScope() + scope.IsRelevant = func(mkline *MkLine) bool { + // See checkfilePackageMakefile. + if !G.Infrastructure && !G.Opts.CheckGlobal { + return !G.Pkgsrc.IsInfra(mkline.Filename) + } + return true + } + + scope.Check(mklines) + + // No note about the redundant variable assignment in bsd.options.mk + // because it is part of the infrastructure, which is filtered out. + t.CheckOutput(diagnostics) + } + + test( + "NOTE: ~/options.mk:2: " + + "Definition of OUTSIDE is redundant because of line 1.") + + t.SetUpCommandLine("-Cglobal") + + test( + "NOTE: ~/options.mk:2: "+ + "Definition of OUTSIDE is redundant because of line 1.", + "NOTE: ~/mk/bsd.options.mk:2: "+ + "Definition of PKG_OPTIONS is redundant because of line 1.") +} + // Branch coverage for info.vari.IsConstant(). The other tests typically // make a variable non-constant by adding conditional assignments between // .if/.endif. But there are other ways. The output of shell commands is @@ -1522,10 +1564,25 @@ func (s *Suite) Test_RedundantScope_hand "NOTE: main.mk:3: Definition of VAR is redundant because of redundant.mk:1.") } +func (s *Suite) Test_RedundantScope_handleVarassign__assign_then_eval(c *check.C) { + t := s.Init(c) + + mklines := t.NewMkLines("mk/bsd.options.mk", + "PKG_OPTIONS=\t# empty", + "PKG_OPTIONS:=\t# empty") + + scope := NewRedundantScope() + scope.Check(mklines) + + t.CheckOutputLines( + "NOTE: mk/bsd.options.mk:2: " + + "Definition of PKG_OPTIONS is redundant because of line 1.") +} + func (s *Suite) Test_includePath_includes(c *check.C) { t := s.Init(c) - path := func(locations ...string) includePath { + path := func(locations ...CurrPath) includePath { return includePath{locations} } @@ -1550,7 +1607,7 @@ func (s *Suite) Test_includePath_include func (s *Suite) Test_includePath_equals(c *check.C) { t := s.Init(c) - path := func(locations ...string) includePath { + path := func(locations ...CurrPath) includePath { return includePath{locations} }