Skip to content

Commit d02ec96

Browse files
committed
🧑‍💻 Output path to feature file and source for steps
Problem: Working with BDD tests can be challenging in large repositories because it is difficult to find the implementation of steps. Patterns of text substitution and multi-line strings make simple greps for step definitions insufficient. Solution: Rather than outputting either the step location or the feature file location, we will instead output the feature file location and optionally the step definition location if available (uses $Given, $When, $Then)
1 parent 1f802e4 commit d02ec96

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

include/GUnit/GSteps.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,20 +592,27 @@ class Steps : public ::testing::EmptyTestEventListener {
592592
throw StepIsAmbiguous{"STEP \"" + expectedStep.second->name +
593593
"\" is ambiguous!"};
594594
}
595-
// update the curret step
595+
// update the current step
596596
current_step_ = i;
597597
const auto name = given_step.second.first.name;
598-
const auto full_file = given_step.second.first.file.empty()
599-
? file_
600-
: given_step.second.first.file;
601-
const auto file =
602-
full_file.substr(full_file.find_last_of("/\\") + 1);
603-
const auto line = expectedStep.second->line;
598+
const auto file = given_step.second.first.file;
604599

605600
std::cout << "\033[0;96m"
606-
<< "[ " << std::right << std::setw(8) << name << " ] "
607-
<< std::left << std::setw(60) << expectedStep.second->name
608-
<< "# " << file << ":" << line << "\033[m" << '\n';
601+
<< "[ " << std::right << std::setw(8) << name << " ] " << std::left << std::setw(60) << expectedStep.second->name << "# ";
602+
603+
{
604+
const auto file = file_.substr(file_.find_last_of("/\\") + 1);
605+
const auto line = expected_step["locations"].back()["line"].template get<int>();
606+
std::cout << file << ":" << line;
607+
}
608+
609+
if (not file.empty()) {
610+
const auto line = given_step.second.first.line;
611+
std::cout << " " << file << ":" << line;
612+
}
613+
614+
std::cout << "\033[m" << '\n';
615+
609616
info_.step = expectedStep.second->name;
610617
given_step.second.second(expectedStep.second->name,
611618
detail::make_table(expected_step));

0 commit comments

Comments
 (0)