-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed pinned build envvar/flag support + list. (#83)
Signed-off-by: Bartlomiej Plotka <[email protected]>
- Loading branch information
Showing
23 changed files
with
304 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/bwplotka/bingo/pkg/bingo" | ||
"github.com/bwplotka/bingo/pkg/runner" | ||
"github.com/bwplotka/bingo/pkg/version" | ||
"github.com/efficientgo/tools/core/pkg/testutil" | ||
|
@@ -22,18 +23,33 @@ const ( | |
defaultGoProxy = "https://proxy.golang.org" | ||
) | ||
|
||
var bingoExpectedCompatibilityOutput = []row{ | ||
{name: "buildable", binName: "buildable-v0.0.0-20210109094001-375d0606849d", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable2", binName: "buildable2-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable_old", binName: "buildable_old-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.0.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.1.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.2.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.5.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "faillint", binName: "faillint-v1.3.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "go-bindata", binName: "go-bindata-v3.1.1+incompatible", pkgVersion: "github.com/go-bindata/go-bindata/[email protected]+incompatible"}, | ||
{name: "wr_buildable", binName: "wr_buildable-v0.0.0-20210109165512-ccbd4039b94a", pkgVersion: "github.com/bwplotka/bingo/testdata/module_with_replace/[email protected]"}, | ||
} | ||
var ( | ||
bingoExpectedCompatibilityOutput = []row{ | ||
{name: "buildable", binName: "buildable-v0.0.0-20210109094001-375d0606849d", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable2", binName: "buildable2-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable_old", binName: "buildable_old-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.0.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.1.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.2.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.5.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "faillint", binName: "faillint-v1.3.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "go-bindata", binName: "go-bindata-v3.1.1+incompatible", pkgVersion: "github.com/go-bindata/go-bindata/[email protected]+incompatible"}, | ||
{name: "wr_buildable", binName: "wr_buildable-v0.0.0-20210109165512-ccbd4039b94a", pkgVersion: "github.com/bwplotka/bingo/testdata/module_with_replace/[email protected]"}, | ||
} | ||
|
||
bingoExpectedCompatibilityOutput_0_4_1 = []row{ | ||
{name: "buildable", binName: "buildable-v0.0.0-20210109094001-375d0606849d", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable2", binName: "buildable2-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "buildable_old", binName: "buildable_old-v0.0.0-20210109093942-2e6391144e85", pkgVersion: "github.com/bwplotka/bingo/testdata/module/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.0.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.1.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.2.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "f2", binName: "f2-v1.5.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "faillint", binName: "faillint-v1.3.0", pkgVersion: "github.com/fatih/[email protected]", buildEnvVars: "CGO_ENABLED=1", buildFlags: "-tags=extended"}, | ||
{name: "go-bindata", binName: "go-bindata-v3.1.1+incompatible", pkgVersion: "github.com/go-bindata/go-bindata/[email protected]+incompatible"}, | ||
{name: "wr_buildable", binName: "wr_buildable-v0.0.0-20210109165512-ccbd4039b94a", pkgVersion: "github.com/bwplotka/bingo/testdata/module_with_replace/[email protected]"}, | ||
} | ||
) | ||
|
||
// TODO(bwplotka): Test running versions. To do so we might want to setup small binary printing Version at each commit. | ||
// $GOBIN has to be set for this test to run properly. | ||
|
@@ -764,6 +780,15 @@ func TestGet(t *testing.T) { | |
|
||
for _, dir := range dirs { | ||
t.Run(dir, func(t *testing.T) { | ||
compatibilityOutput := bingoExpectedCompatibilityOutput | ||
|
||
// Special test case. failint.mod for v0.4.1 version contains line syntax, allowing go build to add those build flags (which does nothing to failint). | ||
// Yet, check if they will get preserved. | ||
// TODO(bwplotka): Design test module that tests better those edge cases instead of installing different 3rdparty real modules. | ||
if dir == "testdata/testproject_with_bingo_v0_4_1" { | ||
compatibilityOutput = bingoExpectedCompatibilityOutput_0_4_1 | ||
} | ||
|
||
for _, isGoProject := range []bool{false, true} { | ||
t.Run(fmt.Sprintf("isGoProject=%v", isGoProject), func(t *testing.T) { | ||
t.Run("Via bingo get all", func(t *testing.T) { | ||
|
@@ -778,7 +803,7 @@ func TestGet(t *testing.T) { | |
p.assertNotChanged(t, defaultModDir) | ||
|
||
testutil.Equals(t, []string{}, g.existingBinaries(t)) | ||
expectBingoListRows(t, bingoExpectedCompatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
expectBingoListRows(t, compatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
|
||
defer p.assertNotChanged(t, defaultModDir) | ||
|
||
|
@@ -792,7 +817,7 @@ func TestGet(t *testing.T) { | |
"faillint-v1.3.0", "go-bindata-v3.1.1+incompatible", | ||
"wr_buildable-v0.0.0-20210109165512-ccbd4039b94a", | ||
}, g.existingBinaries(t)) | ||
expectBingoListRows(t, bingoExpectedCompatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
expectBingoListRows(t, compatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
|
||
// Expect binaries works: | ||
testutil.Equals(t, "module.buildable 2.1\n", g.ExecOutput(t, p.root, filepath.Join(g.gobin, "buildable-v0.0.0-20210109094001-375d0606849d"))) | ||
|
@@ -830,7 +855,7 @@ func TestGet(t *testing.T) { | |
fmt.Println(g.ExecOutput(t, p.root, goBinPath, "get", "f2")) | ||
testutil.Equals(t, []string{"buildable-v0.0.0-20210109094001-375d0606849d", "f2-v1.0.0", "f2-v1.1.0", "f2-v1.2.0", "f2-v1.5.0", "faillint-v1.3.0", "wr_buildable-v0.0.0-20210109165512-ccbd4039b94a"}, g.existingBinaries(t)) | ||
|
||
expectBingoListRows(t, bingoExpectedCompatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
expectBingoListRows(t, compatibilityOutput, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
}) | ||
t.Run("Via go", func(t *testing.T) { | ||
g.Clear(t) | ||
|
@@ -935,7 +960,7 @@ func TestGet(t *testing.T) { | |
fmt.Println(g.ExecOutput(t, p.root, goBinPath, "get", "wr_buildable@none")) | ||
fmt.Println(g.ExecOutput(t, p.root, goBinPath, "get", "go-bindata@none")) | ||
|
||
testutil.Equals(t, "Name\tBinary Name\tPackage @ Version\n----\t-----------\t-----------------", g.ExecOutput(t, p.root, goBinPath, "list")) | ||
expectBingoListRows(t, nil, g.ExecOutput(t, p.root, goBinPath, "list")) | ||
|
||
_, err := os.Stat(filepath.Join(p.root, ".bingo", "Variables.mk")) | ||
testutil.NotOk(t, err) | ||
|
@@ -949,14 +974,16 @@ func TestGet(t *testing.T) { | |
} | ||
|
||
type row struct { | ||
name, binName, pkgVersion string | ||
name, binName, pkgVersion, buildEnvVars, buildFlags string | ||
} | ||
|
||
func expectBingoListRows(t testing.TB, expect []row, output string) { | ||
t.Helper() | ||
|
||
trimmed := strings.TrimLeft(output, "Name\tBinary Name\tPackage @ Version\n----\t-----------\t-----------------\n") // nolint | ||
var got []row | ||
var ( | ||
trimmed = strings.TrimLeft(output, bingo.PackageRenderablesPrintHeader) | ||
got []row | ||
) | ||
for _, line := range strings.Split(trimmed, "\n") { | ||
s := strings.Fields(line) | ||
if len(s) == 0 { | ||
|
@@ -969,17 +996,36 @@ func expectBingoListRows(t testing.TB, expect []row, output string) { | |
if len(s) > 2 { | ||
r.pkgVersion = s[2] | ||
} | ||
if len(s) > 3 { | ||
r.buildEnvVars = s[3] | ||
} | ||
if len(s) > 4 { | ||
r.buildFlags = s[4] | ||
} | ||
got = append(got, r) | ||
} | ||
testutil.Equals(t, expect, got) | ||
} | ||
|
||
func TestExpectBingoListRows(t *testing.T) { | ||
expectBingoListRows(t, []row{ | ||
{name: "f4", binName: "f4-v1.1.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "faillint", binName: "faillint-v1.1.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "faillint", binName: "faillint-v1.0.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "go-bindata", binName: "go-bindata-v3.1.1+incompatible", pkgVersion: "github.com/go-bindata/go-bindata/[email protected]+incompatible"}, | ||
{name: "goimports", binName: "goimports-v0.0.0-20200522201501-cb1345f3a375", pkgVersion: "golang.org/x/tools/cmd/[email protected]"}, | ||
}, "Name\t\t\tBinary Name\t\t\t\t\t\t\tPackage @ Version\n----\t\t\t-----------\t\t\t\t\t\t\t-----------------\nf4\t\t\tf4-v1.1.0\t\t\t\t\t\t\t\thttps-1xa.pages.dev/fatih/[email protected]\t\t\t\t\t\t\t\nfaillint\t\tfaillint-v1.1.0\t\t\t\t\t\thttps-1xa.pages.dev/fatih/[email protected]\t\t\t\t\t\t\t\nfaillint\t\tfaillint-v1.0.0\t\t\t\t\t\thttps-1xa.pages.dev/fatih/[email protected]\t\t\t\t\t\t\t\ngo-bindata\tgo-bindata-v3.1.1+incompatible\t\t\thttps-1xa.pages.dev/go-bindata/go-bindata/[email protected]+incompatible\t\ngoimports\t\tgoimports-v0.0.0-20200522201501-cb1345f3a375\tgolang.org/x/tools/cmd/[email protected]") | ||
{name: "pyright", binName: "copyright-v0.0.0-20210112004814-138d5e5695fe", pkgVersion: "github.com/efficientgo/tools/[email protected]"}, | ||
{name: "embedmd", binName: "embedmd-v1.0.0", pkgVersion: "github.com/campoy/[email protected]", buildEnvVars: "CGO_ENABLED=1", buildFlags: "-tags=lol"}, | ||
{name: "faillint", binName: "faillint-v1.5.0", pkgVersion: "github.com/fatih/[email protected]"}, | ||
{name: "goimports", binName: "goimports-v0.0.0-20210112230658-8b4aab62c064", pkgVersion: "golang.org/x/tools/cmd/[email protected]"}, | ||
{name: "golangci-lint", binName: "golangci-lint-v1.26.0", pkgVersion: "github.com/golangci/golangci-lint/cmd/[email protected]"}, | ||
{name: "mdox", binName: "mdox-v0.2.1", pkgVersion: "github.com/bwplotka/[email protected]"}, | ||
{name: "misspell", binName: "misspell-v0.3.4", pkgVersion: "github.com/client9/misspell/cmd/[email protected]"}, | ||
{name: "proxy", binName: "proxy-v0.10.0", pkgVersion: "github.com/gomods/athens/cmd/[email protected]"}, | ||
}, `Name Binary Name Package @ Version Build EnvVars Build Flags | ||
---- ----------- ----------------- ------------- ----------- | ||
copyright copyright-v0.0.0-20210112004814-138d5e5695fe github.com/efficientgo/tools/[email protected] | ||
embedmd embedmd-v1.0.0 github.com/campoy/[email protected] CGO_ENABLED=1 -tags=lol | ||
faillint faillint-v1.5.0 github.com/fatih/[email protected] | ||
goimports goimports-v0.0.0-20210112230658-8b4aab62c064 golang.org/x/tools/cmd/[email protected] | ||
golangci-lint golangci-lint-v1.26.0 github.com/golangci/golangci-lint/cmd/[email protected] | ||
mdox mdox-v0.2.1 github.com/bwplotka/[email protected] | ||
misspell misspell-v0.3.4 github.com/client9/misspell/cmd/[email protected] | ||
proxy proxy-v0.10.0 github.com/gomods/athens/cmd/[email protected] | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
# Ignore everything | ||
* | ||
|
||
# But not these files: | ||
!.gitignore | ||
!*.mod | ||
!README.md | ||
!Variables.mk | ||
!variables.env | ||
|
||
*tmp.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Project Development Dependencies. | ||
|
||
This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo. | ||
|
||
* Run `bingo get` to install all tools having each own module file in this directory. | ||
* Run `bingo get <tool>` to install <tool> that have own module file in this directory. | ||
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod. | ||
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool. | ||
* For go: Import `.bingo/variables.go` to for variable names. | ||
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies. | ||
|
||
## Requirements | ||
|
||
* Go 1.14+ |
Oops, something went wrong.