Skip to content

Commit

Permalink
ags3,4: tap can check for plan mismatch at runtime
Browse files Browse the repository at this point in the history
the check isn't done in tap itself, but is made as part of run-tests for more flexibility
  • Loading branch information
ericoporto committed Jan 26, 2025
1 parent 3469197 commit f435121
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ags3/auto-test/Game.agf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--DO NOT EDIT THIS FILE. It is automatically generated by the AGS Editor, changing it manually could break your game-->
<AGSEditorDocument Version="3.0.3.2" VersionIndex="3060110" EditorVersion="3.6.1.30">
<AGSEditorDocument Version="3.0.3.2" VersionIndex="3060110" EditorVersion="3.6.1.31">
<Game>
<Settings>
<AllowRelativeAssetResolutions>False</AllowRelativeAssetResolutions>
Expand Down Expand Up @@ -2190,10 +2190,10 @@
<ScriptAndHeader_Script>
<Script>
<FileName>run-tests.asc</FileName>
<Name />
<Description />
<Author />
<Version />
<Name>tap</Name>
<Description>Test Anything Protocol script module.</Description>
<Author>ags team</Author>
<Version>0.3.0</Version>
<Key>423940397</Key>
<IsHeader>False</IsHeader>
</Script>
Expand Down
5 changes: 5 additions & 0 deletions ags3/auto-test/run-tests.asc
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ void RunTests()
if(tap.AnyTestFailed()) {
AbortGame("ERROR: test(s) have failed.");
}

if(tap.PlannedTests != tap.ExecutedTests) {
AbortGame("ERROR: Plan mismatch! Planned %d tests, but ran %d tests.", tap.PlannedTests, tap.ExecutedTests);
}

QuitGame(0);
}
10 changes: 10 additions & 0 deletions ags3/auto-test/tap.asc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ static void tap::Comment(String comment) {
_test_printer(String.Format("# %s", comment));
}

int get_PlannedTests(static tap)
{
return _planned_tests;
}

int get_ExecutedTests(static tap)
{
return _test_count - 1;
}

// refer to the game forum topic or github repository for updated current documentation.
// the below text is only provided as a last resort in case you are offline.
//
Expand Down
6 changes: 6 additions & 0 deletions ags3/auto-test/tap.ash
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ struct tap{

/// add a comment to output
import static void Comment(String comment);

/// gets the number of tests that are planned
import static readonly attribute int PlannedTests;

/// gets the number of tests executed so far
import static readonly attribute int ExecutedTests;
};
8 changes: 4 additions & 4 deletions ags4/auto-test/Game.agf
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,10 @@
<ScriptAndHeader_Script>
<Script>
<FileName>run-tests.asc</FileName>
<Name />
<Description />
<Author />
<Version />
<Name>tap</Name>
<Description>Test Anything Protocol script module.</Description>
<Author>ags team</Author>
<Version>0.3.0</Version>
<Key>423940397</Key>
<IsHeader>False</IsHeader>
</Script>
Expand Down
5 changes: 5 additions & 0 deletions ags4/auto-test/run-tests.asc
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ void RunTests()
if(tap.AnyTestFailed()) {
AbortGame("ERROR: test(s) have failed.");
}

if(tap.PlannedTests != tap.ExecutedTests) {
AbortGame("ERROR: Plan mismatch! Planned %d tests, but ran %d tests.", tap.PlannedTests, tap.ExecutedTests);
}

QuitGame(0);
}
10 changes: 10 additions & 0 deletions ags4/auto-test/tap.asc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ static void tap::Comment(String comment) {
_test_printer(String.Format("# %s", comment));
}

int get_PlannedTests(static tap)
{
return _planned_tests;
}

int get_ExecutedTests(static tap)
{
return _test_count - 1;
}

// refer to the game forum topic or github repository for updated current documentation.
// the below text is only provided as a last resort in case you are offline.
//
Expand Down
6 changes: 6 additions & 0 deletions ags4/auto-test/tap.ash
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ struct tap{

/// add a comment to output
import static void Comment(String comment);

/// gets the number of tests that are planned
import static readonly attribute int PlannedTests;

/// gets the number of tests executed so far
import static readonly attribute int ExecutedTests;
};

0 comments on commit f435121

Please sign in to comment.