var packageRE = regexp.MustCompile(`(?m)^package (\w+)`)
-func goDirPackages(longdir string) ([][]string, error) {
+// If singlefilepkgs is set, each file is considered a separate package
+// even if the package names are the same.
+func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) {
files, err := goDirFiles(longdir)
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot find package name in %s", name)
}
i, ok := m[pkgname[1]]
- if !ok {
+ if singlefilepkgs || !ok {
i = len(pkgs)
pkgs = append(pkgs, nil)
m[pkgname[1]] = i
var args, flags []string
wantError := false
+ singlefilepkgs := false
f := strings.Fields(action)
if len(f) > 0 {
action = f[0]
args = f[1:]
}
+ // TODO: Clean up/simplify this switch statement.
switch action {
case "rundircmpout":
action = "rundir"
case "errorcheck", "errorcheckdir", "errorcheckoutput":
t.action = action
wantError = true
- for len(args) > 0 && strings.HasPrefix(args[0], "-") {
- if args[0] == "-0" {
- wantError = false
- } else {
- flags = append(flags, args[0])
- }
- args = args[1:]
- }
case "skip":
if *runSkips {
break
return
}
+ // collect flags
+ for len(args) > 0 && strings.HasPrefix(args[0], "-") {
+ switch args[0] {
+ case "-0":
+ wantError = false
+ case "-s":
+ singlefilepkgs = true
+ default:
+ flags = append(flags, args[0])
+ }
+ args = args[1:]
+ }
+
t.makeTempDir()
if !*keep {
defer os.RemoveAll(t.tempDir)
case "compiledir":
// Compile all files in the directory in lexicographic order.
longdir := filepath.Join(cwd, t.goDirName())
- pkgs, err := goDirPackages(longdir)
+ pkgs, err := goDirPackages(longdir, singlefilepkgs)
if err != nil {
t.err = err
return
// errorcheck all files in lexicographic order
// useful for finding importing errors
longdir := filepath.Join(cwd, t.goDirName())
- pkgs, err := goDirPackages(longdir)
+ pkgs, err := goDirPackages(longdir, singlefilepkgs)
if err != nil {
t.err = err
return
// Compile all files in the directory in lexicographic order.
// then link as if the last file is the main package and run it
longdir := filepath.Join(cwd, t.goDirName())
- pkgs, err := goDirPackages(longdir)
+ pkgs, err := goDirPackages(longdir, singlefilepkgs)
if err != nil {
t.err = err
return