Skip to content

Commit

Permalink
feat(integration-tests): Option to print debug messages from integrat…
Browse files Browse the repository at this point in the history
…ion tests (endless-sky#10833)
  • Loading branch information
petervdmeer authored Dec 19, 2024
1 parent 3543ed5 commit bae0b9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.
#include <SDL2/SDL.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
Expand All @@ -50,6 +51,7 @@ namespace {
{Test::TestStep::Type::ASSERT, "assert"},
{Test::TestStep::Type::BRANCH, "branch"},
{Test::TestStep::Type::CALL, "call"},
{Test::TestStep::Type::DEBUG, "debug"},
{Test::TestStep::Type::INJECT, "inject"},
{Test::TestStep::Type::INPUT, "input"},
{Test::TestStep::Type::LABEL, "label"},
Expand Down Expand Up @@ -244,6 +246,16 @@ void Test::LoadSequence(const DataNode &node)
else
step.nameOrLabel = child.Token(1);
break;
case TestStep::Type::DEBUG:
if(child.Size() < 2)
{
status = Status::BROKEN;
child.PrintTrace("Error: Invalid use of \"debug\" without an actual message to print:");
return;
}
else
step.nameOrLabel = child.Token(1);
break;
case TestStep::Type::INJECT:
if(child.Size() < 2)
{
Expand Down Expand Up @@ -471,6 +483,12 @@ void Test::Step(TestContext &context, PlayerInfo &player, Command &commandToGive
}
continueGameLoop = true;
break;
case TestStep::Type::DEBUG:
// Print debugging output directly to the terminal.
cout << stepToRun.nameOrLabel << endl;
cout.flush();
++(context.callstack.back().step);
break;
case TestStep::Type::INJECT:
{
// Lookup the data and inject it in the game or into the environment.
Expand Down
2 changes: 2 additions & 0 deletions source/test/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Test {
BRANCH,
// Step that calls another test to handle some generic common actions.
CALL,
// Step that prints a debug-message to the output.
DEBUG,
// Step that adds game-data, either in the config-directories or in the game directly.
INJECT,
// Step that performs input (key, mouse, command). Does cause the game to step (to process the inputs).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ test "Afterburner-flight - Simple depart land"
inject "burning flyers save"
call "Load First Savegame"
call "Depart"
debug "Departed from the planet"
# Wait for 10 seconds to drift away from the planet.
apply
"test: steps to wait" = 20
Expand All @@ -121,6 +122,8 @@ test "Afterburner-flight - Simple depart land"
"test: steps to wait" > 0
navigate
"travel destination" Ruin
debug "Start landing"
call "Land"
debug "Done landing"
assert
"flagship landed" == 1

0 comments on commit bae0b9c

Please sign in to comment.