pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools/pkglint/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Wed Mar 29 07:47:19 UTC 2023

Added Files:
        pkgsrc/pkgtools/pkglint/files: project.go project_test.go

Log Message:
pkglint: add missing files from previous commit


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkglint/files/project.go \
    pkgsrc/pkgtools/pkglint/files/project_test.go

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: pkgsrc/pkgtools/pkglint/files/project.go
diff -u /dev/null pkgsrc/pkgtools/pkglint/files/project.go:1.1
--- /dev/null   Wed Mar 29 07:47:19 2023
+++ pkgsrc/pkgtools/pkglint/files/project.go    Wed Mar 29 07:47:19 2023
@@ -0,0 +1,42 @@
+package pkglint
+
+// Project defines a larger collection of makefiles that establishes
+// conventions on variable names, variable types, deprecated variables
+// and so on.
+//
+// Pkglint initially started as a pkgsrc-only tool, but since it parses,
+// analyzes and formats makefiles, these parts are useful outside pkgsrc
+// as well.
+type Project interface {
+
+       // Deprecated determines whether the variable is deprecated,
+       // and if so, what should be done instead.
+       Deprecated(varname string) string
+
+       // Types determines the types of variables.
+       Types() *VarTypeRegistry
+}
+
+type NetBSDProject struct {
+       deprecated map[string]string
+       types      VarTypeRegistry
+}
+
+func NewNetBSDProject() *NetBSDProject {
+       return &NetBSDProject{
+               map[string]string{},
+               NewVarTypeRegistry(),
+       }
+}
+
+func (p NetBSDProject) Deprecated(varname string) string {
+       deprecated := p.deprecated
+       if instead := deprecated[varname]; instead != "" {
+               return instead
+       }
+       return deprecated[varnameCanon(varname)]
+}
+
+func (p NetBSDProject) Types() *VarTypeRegistry {
+       return &p.types
+}
Index: pkgsrc/pkgtools/pkglint/files/project_test.go
diff -u /dev/null pkgsrc/pkgtools/pkglint/files/project_test.go:1.1
--- /dev/null   Wed Mar 29 07:47:19 2023
+++ pkgsrc/pkgtools/pkglint/files/project_test.go       Wed Mar 29 07:47:19 2023
@@ -0,0 +1,39 @@
+package pkglint
+
+import "gopkg.in/check.v1"
+
+func (s *Suite) Test_NewNetBSDProject(c *check.C) {
+       t := s.Init(c)
+
+       project := NewNetBSDProject()
+
+       t.CheckNotNil(project.deprecated)
+       t.CheckEquals(0, len(project.deprecated))
+}
+
+func (s *Suite) Test_NetBSDProject_Deprecated(c *check.C) {
+       t := s.Init(c)
+
+       project := NewNetBSDProject()
+       project.deprecated["DEPRECATED"] = "Use NEW_AND_SHINY instead."
+       G.Project = project
+       mklines := t.NewMkLines("filename.mk",
+               MkCvsID,
+               "DEPRECATED=\t${DEPRECATED}")
+
+       mklines.Check()
+
+       t.CheckOutputLines(
+               "WARN: filename.mk:2: Definition of DEPRECATED is deprecated. Use NEW_AND_SHINY instead.",
+               "WARN: filename.mk:2: Use of \"DEPRECATED\" is deprecated. Use NEW_AND_SHINY instead.")
+}
+
+func (s *Suite) Test_NetBSDProject_Types(c *check.C) {
+       t := s.Init(c)
+
+       project := NewNetBSDProject()
+       project.Types().acl("VAR", BtUnknown, NoVartypeOptions, "*.mk: append")
+
+       t.CheckEquals(project.Types().Canon("VAR").basicType, BtUnknown)
+       t.CheckEquals(project.Types().Canon("UNDEFINED"), (*Vartype)(nil))
+}



Home | Main Index | Thread Index | Old Index