Skip to content

Commit

Permalink
add test for running with feature contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kaswen-Wilk committed Jul 23, 2022
1 parent 239dd4b commit 25813de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
6 changes: 3 additions & 3 deletions run.go
Expand Up @@ -227,10 +227,10 @@ func runWithOptions(suiteName string, runner runner, opt Options) int {
runner.fmt = multiFmt.FormatterFunc(suiteName, output)

var err error
if len(opt.Paths) > 0 {
runner.features, err = parser.ParseFeatures(opt.Tags, opt.Paths)
} else {
if len(opt.FeatureContents) > 0 {
runner.features, err = parser.ParseFromBytes(opt.Tags, opt.FeatureContents)
} else {
runner.features, err = parser.ParseFeatures(opt.Tags, opt.Paths)
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
40 changes: 40 additions & 0 deletions run_test.go
Expand Up @@ -263,6 +263,46 @@ func Test_ByDefaultRunsFeaturesPath(t *testing.T) {
assert.Equal(t, exitSuccess, status)
}

func Test_RunsWithFeatureContentsOption(t *testing.T) {
items, err := ioutil.ReadDir("./features")
require.NoError(t, err)

featureContents := make(map[string][]byte)
for _, item := range items {
if !item.IsDir() && strings.Contains(item.Name(), ".feature"){
contents, err := os.ReadFile("./features/"+item.Name())
require.NoError(t, err)
featureContents[item.Name()] = contents
}
}

opts := Options{
Format: "progress",
Output: ioutil.Discard,
Strict: true,
FeatureContents: featureContents,
}

status := TestSuite{
Name: "fails",
ScenarioInitializer: func(_ *ScenarioContext) {},
Options: &opts,
}.Run()

// should fail in strict mode due to undefined steps
assert.Equal(t, exitFailure, status)

opts.Strict = false
status = TestSuite{
Name: "succeeds",
ScenarioInitializer: func(_ *ScenarioContext) {},
Options: &opts,
}.Run()

// should succeed in non strict mode due to undefined steps
assert.Equal(t, exitSuccess, status)
}

func bufErrorPipe(t *testing.T) (io.ReadCloser, func()) {
stderr := os.Stderr
r, w, err := os.Pipe()
Expand Down

0 comments on commit 25813de

Please sign in to comment.