Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for missing test files and raise a more helpful error #468

Merged
merged 26 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de1893e
Add example about incorrect project structure
ALCooper12 Nov 10, 2021
9346d00
Added some debugging statements
ALCooper12 Nov 22, 2021
6a2fd39
Merge branch 'fix-issue#383' of https://github.com/ALCooper12/godog i…
ALCooper12 Jan 17, 2022
d71481b
Update go.sum for example project
ALCooper12 Jan 17, 2022
1b728fa
Made a cmd_run_test.go file in order to test and run the builderAndRu…
ALCooper12 Jan 24, 2022
da8d6a3
Merge branch 'cucumber:main' into fix-issue#383
ALCooper12 Jan 24, 2022
2322466
Merge branch 'main' into fix-issue#383
ALCooper12 Feb 3, 2022
3686f1f
added new assertion test
ALCooper12 Feb 3, 2022
f9ac07c
Merge branch 'fix-issue#383' of https://github.com/ALCooper12/godog i…
ALCooper12 Feb 3, 2022
ead4892
Matt and I added debugging
ALCooper12 Feb 23, 2022
378966a
Matt and I tried to logging through the cobra command
ALCooper12 Feb 23, 2022
1492e3e
Merge branch 'main' into fix-issue#383
ALCooper12 Feb 23, 2022
940f956
Improved some debugging
ALCooper12 Mar 9, 2022
e5b2693
Add a failing test for Builder that reproduces #383
mattwynne Mar 9, 2022
b5d602e
added new test for IncorrectProjectStructure #383
ALCooper12 Mar 30, 2022
b0fb450
Revert "Add a failing test for Builder that reproduces #383"
mattwynne Apr 6, 2022
bf6f71b
Merge branch 'cucumber:fix-issue#383' into fix-issue#383
ALCooper12 Apr 6, 2022
1f85cfa
ignored vscode files
ALCooper12 Apr 6, 2022
ab87251
Merge branch 'fix-issue#383' of https://github.com/ALCooper12/godog i…
ALCooper12 Apr 6, 2022
17e72cf
undid debugging changes
ALCooper12 Apr 6, 2022
a0f70bc
undid debugging changes
ALCooper12 Apr 6, 2022
2e67172
removed redundant test
ALCooper12 Apr 6, 2022
a70f51c
Merge branch 'main' into fix-issue#383
mattwynne Apr 20, 2022
49d349d
added check for incorrect project structure
ALCooper12 Apr 20, 2022
77829af
Merge branch 'fix-issue#383' of https://github.com/ALCooper12/godog i…
ALCooper12 Apr 20, 2022
5468a92
Update internal/builder/builder_test.go
vearutop Apr 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Gopkg.toml

.DS_Store
.idea
.vscode

_artifacts
6 changes: 6 additions & 0 deletions _examples/incorrect-project-structure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This example is to help reproduce issue [#383](https://github.com/cucumber/godog/issues/383)

To run the example:

cd _examples/incorrect-project-structure
go run ../../cmd/godog
7 changes: 7 additions & 0 deletions _examples/incorrect-project-structure/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module incorrect-project-structure

go 1.13

require github.com/cucumber/godog v0.12.0

replace github.com/cucumber/godog => ../../
315 changes: 315 additions & 0 deletions _examples/incorrect-project-structure/go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions _examples/incorrect-project-structure/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/cucumber/godog"

func InitializeScenario(ctx *godog.ScenarioContext) {

}
5 changes: 5 additions & 0 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func Build(bin string) error {
break
}

if strings.Contains(string(testOutput), "[no test files]") {
return fmt.Errorf("incorrect project structure: no test files found")
}

// may not locate it in output
if workdir == testdir {
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(testOutput))
Expand Down Expand Up @@ -182,6 +186,7 @@ func Build(bin string) error {
// we do not depend on CGO so a lot of checks are not necessary
linkerCfg := filepath.Join(testdir, "importcfg.link")
compilerCfg := linkerCfg

if vendored != nil {
data, err := ioutil.ReadFile(linkerCfg)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions internal/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Test_GodogBuild(t *testing.T) {
t.Run("WithinGopath", testWithinGopath)
t.Run("WithVendoredGodogWithoutModule", testWithVendoredGodogWithoutModule)
t.Run("WithVendoredGodogAndMod", testWithVendoredGodogAndMod)
t.Run("WithIncorrectProjectStructure", testWithIncorrectProjectStructure)

t.Run("WithModule", func(t *testing.T) {
t.Run("OutsideGopathAndHavingOnlyFeature", testOutsideGopathAndHavingOnlyFeature)
Expand Down Expand Up @@ -135,6 +136,13 @@ func main() {
}
`

var emptyBuilderTestFile = `package godogs

import "github.com/cucumber/godog"

func InitializeScenario(ctx *godog.ScenarioContext) {}
`

var builderModFile = `module godogs`

func buildTestPackage(dir string, files map[string]string) error {
Expand Down Expand Up @@ -237,6 +245,38 @@ func testWithoutTestSourceNotInGoPath(t *testing.T) {
builderTC.run(t)
}

func testWithIncorrectProjectStructure(t *testing.T) {
dir := filepath.Join(os.TempDir(), t.Name(), "godogs")
files := map[string]string{
"godogs.go": emptyBuilderTestFile,
"go.mod": builderModFile,
}

err := buildTestPackage(dir, files)
defer os.RemoveAll(dir)
require.Nil(t, err)

prevDir, err := os.Getwd()
require.Nil(t, err)
err = os.Chdir(dir)
require.Nil(t, err)
defer os.Chdir(prevDir)

testBin, err := filepath.Abs(filepath.Join(dir, "godog.test"))
require.Nil(t, err)

if build.Default.GOOS == "windows" {
testBin += ".exe"
}

// call the builder - we should get an error
err = builder.Build(testBin)
// check that we even got an error at all
require.NotNil(t, err)
// now check the details of the error message
require.EqualError(t, err, "incorrect project structure: no test files found")
}

func testWithinGopath(t *testing.T) {
builderTC := builderTestCase{}

Expand Down