[BACK]Return to shell_test.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

File: [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files / Attic / shell_test.go (download)

Revision 1.2, Wed Dec 2 21:46:46 2015 UTC (8 years, 4 months ago) by rillig
Branch: MAIN
Changes since 1.1: +2 -2 lines

Updated pkglint to 5.1.

Changes since 5.0:
* Fixed --autofix mode (it hadn't been enabled before)
* The --autofix mode now advertises itself when it can do something
* The --autofix mode now adds missing empty lines to patch files
  (only in the leading text section, not in the actual patch content)
* Made --autofix code simpler ({prepend,append}{Before,After} was not
  really needed)
* Fixed unit tests to report invalid command lines
* Added some more unit tests

package main

import (
	check "gopkg.in/check.v1"
)

func (s *Suite) TestSplitIntoShellwords_LineContinuation(c *check.C) {
	line := NewLine("fname", "1", "dummy", nil)

	words, rest := splitIntoShellwords(line, "if true; then \\")

	c.Check(words, check.DeepEquals, []string{"if", "true", ";", "then"})
	c.Check(rest, equals, "\\")

	words, rest = splitIntoShellwords(line, "pax -s /.*~$$//g")

	c.Check(words, check.DeepEquals, []string{"pax", "-s", "/.*~$$//g"})
	c.Check(rest, equals, "")
}

func (s *Suite) TestChecklineMkShelltext(c *check.C) {
	G.mkContext = newMkContext()
	line := NewLine("fname", "1", "dummy", nil)

	NewMkShellLine(line).checklineMkShelltext("@# Comment")
}

func (s *Suite) TestChecklineMkShellword(c *check.C) {
	s.UseCommandLine(c, "-Wall")
	G.globalData.InitVartypes()
	line := NewLine("fname", "1", "dummy", nil)

	c.Check(matches("${list}", `^`+reVarname+`$`), equals, true)
	c.Check(matches("${list}", `^`+reVarnameDirect+`$`), equals, false)

	checklineMkShellword(line, "${${list}}", false)

	c.Check(s.Output(), equals, "")

	checklineMkShellword(line, "\"$@\"", false)

	c.Check(s.Output(), equals, "WARN: fname:1: Please use \"${.TARGET}\" instead of \"$@\".\n")
}

func (s *Suite) TestShelltextContext_CheckCommandStart(c *check.C) {
	s.UseCommandLine(c, "-Wall")
	G.globalData.tools = map[string]bool{"echo": true}
	G.globalData.vartools = map[string]string{"echo": "ECHO"}
	G.globalData.toolsVarRequired = map[string]bool{"echo": true}
	G.mkContext = newMkContext()
	line := NewLine("fname", "3", "dummy", nil)

	checklineMkShellcmd(line, "echo \"hello, world\"")

	c.Check(s.Output(), equals, ""+
		"WARN: fname:3: The \"echo\" tool is used but not added to USE_TOOLS.\n"+
		"WARN: fname:3: Please use \"${ECHO}\" instead of \"echo\".\n")
}