# 'go mod why -m' should reject malformed module paths before loading # the module graph. ! go mod why -m golang.org/x/text/ stderr '^go mod why: malformed module path "golang.org/x/text/": trailing slash$' # Module patterns should validate the literal path around each wildcard. ! go mod why -m golang.org//x/... stderr '^go mod why: malformed module path "golang.org//x/...": double slash$' ! go mod why -m golang.org/...//.../text stderr '^go mod why: malformed module path "golang.org/...//.../text": double slash$' # Populate go.sum. go mod tidy cp go.mod go.mod.orig go list -test all stdout rsc.io/quote stdout golang.org/x/text/language # why a package? go mod why golang.org/x/text/language cmp stdout why-language.txt # why a module? go mod why -m golang.org... cmp stdout why-text-module.txt # Module patterns may contain multiple wildcards. go mod why -m golang...org/.../te... cmp stdout why-text-module.txt # Module paths that are valid only when replaced should be accepted. ! go mod why -m mymodule/nested cmp stdout why-replaced-module.txt # why a package used only in tests? go mod why rsc.io/testonly cmp stdout why-testonly.txt # why a module used only in a test of a dependency? go mod why -m rsc.io/testonly cmp stdout why-testonly.txt # test package not needed ! go mod why golang.org/x/text/unused cmp stdout why-unused.txt # vendor doesn't use packages used only in tests. ! go mod why -vendor rsc.io/testonly cmp stdout why-vendor.txt # vendor doesn't use modules used only in tests. ! go mod why -vendor -m rsc.io/testonly cmp stdout why-vendor-module.txt # test multiple packages ! go mod why golang.org/x/text/language golang.org/x/text/unused cmp stdout why-both.txt # test multiple modules go mod why -m rsc.io/quote rsc.io/sampler cmp stdout why-both-module.txt # test multiple modules with an unused module ! go mod why -m rsc.io/quote mymodule/nested cmp stdout why-both-module-unused.txt # package in a module that isn't even in the module graph # (https://golang.org/issue/26977) ! go mod why rsc.io/fortune cmp stdout why-missing.txt # None of these command should have changed the go.mod file. cmp go.mod go.mod.orig -- go.mod -- module mymodule require rsc.io/quote v1.5.2 replace mymodule/nested => ./nested -- nested/go.mod -- module mymodule/nested -- x/x.go -- package x import _ "mymodule/z" -- y/y.go -- package y -- y/y_test.go -- package y import _ "rsc.io/quote" -- z/z.go -- package z import _ "mymodule/y" -- why-language.txt -- # golang.org/x/text/language mymodule/y mymodule/y.test rsc.io/quote rsc.io/sampler golang.org/x/text/language -- why-unused.txt -- # golang.org/x/text/unused (main module does not need package golang.org/x/text/unused) -- why-text-module.txt -- # golang.org/x/text mymodule/y mymodule/y.test rsc.io/quote rsc.io/sampler golang.org/x/text/language -- why-replaced-module.txt -- # mymodule/nested (main module does not need module mymodule/nested) -- why-testonly.txt -- # rsc.io/testonly mymodule/y mymodule/y.test rsc.io/quote rsc.io/sampler rsc.io/sampler.test rsc.io/testonly -- why-vendor.txt -- # rsc.io/testonly (main module does not need to vendor package rsc.io/testonly) -- why-vendor-module.txt -- # rsc.io/testonly (main module does not need to vendor module rsc.io/testonly) -- why-both.txt -- # golang.org/x/text/language mymodule/y mymodule/y.test rsc.io/quote rsc.io/sampler golang.org/x/text/language # golang.org/x/text/unused (main module does not need package golang.org/x/text/unused) -- why-both-module.txt -- # rsc.io/quote mymodule/y mymodule/y.test rsc.io/quote # rsc.io/sampler mymodule/y mymodule/y.test rsc.io/quote rsc.io/sampler -- why-both-module-unused.txt -- # rsc.io/quote mymodule/y mymodule/y.test rsc.io/quote # mymodule/nested (main module does not need module mymodule/nested) -- why-missing.txt -- # rsc.io/fortune (main module does not need package rsc.io/fortune)