Skip to content

Commit

Permalink
Add a failing test for Builder that reproduces cucumber#383
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwynne committed Mar 9, 2022
1 parent 940f956 commit e5b2693
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal/builder/builder_test.go
Expand Up @@ -2,6 +2,7 @@ package builder_test

import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"os"
Expand All @@ -25,6 +26,7 @@ func Test_GodogBuild(t *testing.T) {
t.Run("WithinGopath", testWithinGopath)
t.Run("WithVendoredGodogWithoutModule", testWithVendoredGodogWithoutModule)
t.Run("WithVendoredGodogAndMod", testWithVendoredGodogAndMod)
t.Run("WithMissingTestFile", testWithMissingTestFile)

t.Run("WithModule", func(t *testing.T) {
t.Run("OutsideGopathAndHavingOnlyFeature", testOutsideGopathAndHavingOnlyFeature)
Expand All @@ -45,6 +47,14 @@ var builderFeatureFile = `Feature: eat godogs
Then there should be 7 remaining
`

var emptyBuilderTestFile = `package main
import "github.com/cucumber/godog"
func InitializeScenario(ctx *godog.ScenarioContext) {
}`

var builderTestFile = `package godogs
import (
Expand Down Expand Up @@ -292,6 +302,34 @@ func testWithVendoredGodogWithoutModule(t *testing.T) {
builderTC.run(t)
}

func testWithMissingTestFile(t *testing.T) {
dir := filepath.Join(os.TempDir(), t.Name(), "my-app")
files := map[string]string{
"main.go": emptyBuilderTestFile,
"go.mod": builderModFile,
}
err := buildTestPackage(dir, files)
defer os.RemoveAll(dir)
require.Nil(t, err)
fmt.Printf("\nTests working in %s\n\n", dir)

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"
}

err = builder.Build(testBin)
require.Contains(t, err.Error(), "Incorrect project structure")
}

type builderTestCase struct {
dir string
files map[string]string
Expand Down

0 comments on commit e5b2693

Please sign in to comment.