Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
Add ListPackages case w/slashes in root path
Browse files Browse the repository at this point in the history
Not covering this basic aspect of how real project roots actually work
allowed a windows bug to hide until real data came through - #146.
  • Loading branch information
sdboyer committed Jan 19, 2017
1 parent 69fdac2 commit 01f1ccc
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 37 deletions.
13 changes: 13 additions & 0 deletions _testdata/src/github.com/example/varied/locals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"github.com/example/varied/namemismatch"
"github.com/example/varied/otherpath"
"github.com/example/varied/simple"
)

var (
_ = simple.S
_ = nm.V
_ = otherpath.O
)
12 changes: 12 additions & 0 deletions _testdata/src/github.com/example/varied/m1p/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package m1p

import (
"sort"

"github.com/sdboyer/gps"
)

var (
M = sort.Strings
_ = gps.Solve
)
11 changes: 11 additions & 0 deletions _testdata/src/github.com/example/varied/m1p/b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package m1p

import (
"os"
"sort"
)

var (
_ = sort.Strings
_ = os.PathSeparator
)
9 changes: 9 additions & 0 deletions _testdata/src/github.com/example/varied/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"net/http"
)

var (
_ = http.Client
)
12 changes: 12 additions & 0 deletions _testdata/src/github.com/example/varied/namemismatch/nm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nm

import (
"os"

"github.com/Masterminds/semver"
)

var (
V = os.FileInfo
_ = semver.Constraint
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package otherpath

import "github.com/example/varied/m1p"

var O = m1p.M
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package another

import "hash"

var (
H = hash.Hash
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package another

import "encoding/binary"

var (
_ = binary.PutVarint
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package another

import "github.com/example/varied/m1p"

var _ = m1p.M
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package simple

import "github.com/example/varied/simple/another"

var (
_ = another.H
)
12 changes: 12 additions & 0 deletions _testdata/src/github.com/example/varied/simple/simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package simple

import (
"go/parser"

"github.com/sdboyer/gps"
)

var (
_ = parser.ParseFile
S = gps.Prepare
)
74 changes: 37 additions & 37 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func TestListPackages(t *testing.T) {

func TestListExternalImports(t *testing.T) {
// There's enough in the 'varied' test case to test most of what matters
vptree, err := ListPackages(filepath.Join(getwd(t), "_testdata", "src", "varied"), "varied")
vptree, err := ListPackages(filepath.Join(getwd(t), "_testdata", "src", "github.com", "example", "varied"), "github.com/example/varied")
if err != nil {
t.Fatalf("listPackages failed on varied test case: %s", err)
}
Expand Down Expand Up @@ -999,15 +999,15 @@ func TestListExternalImports(t *testing.T) {
// should have the same effect as ignoring main
name = "ignore the root"
ignore = map[string]bool{
"varied": true,
"github.com/example/varied": true,
}
except("net/http")
validate()

// now drop a more interesting one
name = "ignore simple"
ignore = map[string]bool{
"varied/simple": true,
"github.com/example/varied/simple": true,
}
// we get github.com/sdboyer/gps from m1p, too, so it should still be there
except("go/parser")
Expand All @@ -1016,8 +1016,8 @@ func TestListExternalImports(t *testing.T) {
// now drop two
name = "ignore simple and namemismatch"
ignore = map[string]bool{
"varied/simple": true,
"varied/namemismatch": true,
"github.com/example/varied/simple": true,
"github.com/example/varied/namemismatch": true,
}
except("go/parser", "github.com/Masterminds/semver")
validate()
Expand All @@ -1041,8 +1041,8 @@ func TestListExternalImports(t *testing.T) {
// ignore two that should knock out gps
name = "ignore both importers"
ignore = map[string]bool{
"varied/simple": true,
"varied/m1p": true,
"github.com/example/varied/simple": true,
"github.com/example/varied/m1p": true,
}
except("sort", "github.com/sdboyer/gps", "go/parser")
validate()
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func TestListExternalImports(t *testing.T) {

func TestExternalReach(t *testing.T) {
// There's enough in the 'varied' test case to test most of what matters
vptree, err := ListPackages(filepath.Join(getwd(t), "_testdata", "src", "varied"), "varied")
vptree, err := ListPackages(filepath.Join(getwd(t), "_testdata", "src", "github.com", "example", "varied"), "github.com/example/varied")
if err != nil {
t.Fatalf("listPackages failed on varied test case: %s", err)
}
Expand Down Expand Up @@ -1108,12 +1108,12 @@ func TestExternalReach(t *testing.T) {
}

all := map[string][]string{
"varied": {"encoding/binary", "github.com/Masterminds/semver", "github.com/sdboyer/gps", "go/parser", "hash", "net/http", "os", "sort"},
"varied/m1p": {"github.com/sdboyer/gps", "os", "sort"},
"varied/namemismatch": {"github.com/Masterminds/semver", "os"},
"varied/otherpath": {"github.com/sdboyer/gps", "os", "sort"},
"varied/simple": {"encoding/binary", "github.com/sdboyer/gps", "go/parser", "hash", "os", "sort"},
"varied/simple/another": {"encoding/binary", "github.com/sdboyer/gps", "hash", "os", "sort"},
"github.com/example/varied": {"encoding/binary", "github.com/Masterminds/semver", "github.com/sdboyer/gps", "go/parser", "hash", "net/http", "os", "sort"},
"github.com/example/varied/m1p": {"github.com/sdboyer/gps", "os", "sort"},
"github.com/example/varied/namemismatch": {"github.com/Masterminds/semver", "os"},
"github.com/example/varied/otherpath": {"github.com/sdboyer/gps", "os", "sort"},
"github.com/example/varied/simple": {"encoding/binary", "github.com/sdboyer/gps", "go/parser", "hash", "os", "sort"},
"github.com/example/varied/simple/another": {"encoding/binary", "github.com/sdboyer/gps", "hash", "os", "sort"},
}
// build a map to validate the exception inputs. do this because shit is
// hard enough to keep track of that it's preferable not to have silent
Expand Down Expand Up @@ -1190,13 +1190,13 @@ func TestExternalReach(t *testing.T) {
// turn off main pkgs, which necessarily doesn't affect anything else
name = "no main"
main = false
except("varied")
except("github.com/example/varied")
validate()

// ignoring the "varied" pkg has same effect as disabling main pkgs
name = "ignore root"
ignore = map[string]bool{
"varied": true,
"github.com/example/varied": true,
}
main = true
validate()
Expand All @@ -1208,20 +1208,20 @@ func TestExternalReach(t *testing.T) {
tests = false
ignore = nil
except(
"varied encoding/binary",
"varied/simple encoding/binary",
"varied/simple/another encoding/binary",
"varied/otherpath github.com/sdboyer/gps os sort",
"github.com/example/varied encoding/binary",
"github.com/example/varied/simple encoding/binary",
"github.com/example/varied/simple/another encoding/binary",
"github.com/example/varied/otherpath github.com/sdboyer/gps os sort",
)

// almost the same as previous, but varied just goes away completely
name = "no main or tests"
main = false
except(
"varied",
"varied/simple encoding/binary",
"varied/simple/another encoding/binary",
"varied/otherpath github.com/sdboyer/gps os sort",
"github.com/example/varied",
"github.com/example/varied/simple encoding/binary",
"github.com/example/varied/simple/another encoding/binary",
"github.com/example/varied/otherpath github.com/sdboyer/gps os sort",
)
validate()

Expand All @@ -1232,38 +1232,38 @@ func TestExternalReach(t *testing.T) {
// varied/simple
name = "ignore varied/simple"
ignore = map[string]bool{
"varied/simple": true,
"github.com/example/varied/simple": true,
}
except(
// root pkg loses on everything in varied/simple/another
"varied hash encoding/binary go/parser",
"varied/simple",
"github.com/example/varied hash encoding/binary go/parser",
"github.com/example/varied/simple",
)
validate()

// widen the hole by excluding otherpath
name = "ignore varied/{otherpath,simple}"
ignore = map[string]bool{
"varied/otherpath": true,
"varied/simple": true,
"github.com/example/varied/otherpath": true,
"github.com/example/varied/simple": true,
}
except(
// root pkg loses on everything in varied/simple/another and varied/m1p
"varied hash encoding/binary go/parser github.com/sdboyer/gps sort",
"varied/otherpath",
"varied/simple",
"github.com/example/varied hash encoding/binary go/parser github.com/sdboyer/gps sort",
"github.com/example/varied/otherpath",
"github.com/example/varied/simple",
)
validate()

// remove namemismatch, though we're mostly beating a dead horse now
name = "ignore varied/{otherpath,simple,namemismatch}"
ignore["varied/namemismatch"] = true
ignore["github.com/example/varied/namemismatch"] = true
except(
// root pkg loses on everything in varied/simple/another and varied/m1p
"varied hash encoding/binary go/parser github.com/sdboyer/gps sort os github.com/Masterminds/semver",
"varied/otherpath",
"varied/simple",
"varied/namemismatch",
"github.com/example/varied hash encoding/binary go/parser github.com/sdboyer/gps sort os github.com/Masterminds/semver",
"github.com/example/varied/otherpath",
"github.com/example/varied/simple",
"github.com/example/varied/namemismatch",
)
validate()
}
Expand Down

0 comments on commit 01f1ccc

Please sign in to comment.