Skip to content

Commit

Permalink
Refactor testCampaignLuaFile::ScriptVersion
Browse files Browse the repository at this point in the history
Remove confusing "!load()" check when comment says it should succeed.
Build a single lua file and just append to it during test
  • Loading branch information
Flamefire committed Jun 6, 2024
1 parent 985dea7 commit 13a991c
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions tests/s25Main/campaign/testCampaignLuaFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,28 @@ BOOST_AUTO_TEST_SUITE(CampaignLuaFile)

BOOST_AUTO_TEST_CASE(ScriptVersion)
{
// No getRequiredLuaVersion
rttr::test::TmpFolder tmp;
const auto campaignFile = tmp / "campaign.lua";
{
rttr::test::TmpFolder tmp;
{
bnw::ofstream file(tmp / "campaign.lua");
file << "";
}
bnw::ofstream file(campaignFile);

file << "campaign ={\
version = \"1\",\
author = \"Max Meier\",\
name = \"Meine Kampagne\",\
shortDescription = \"Sehr kurze Beschreibung\",\
longDescription = \"Das ist die lange Beschreibung\",\
image = \"<RTTR_GAME>/GFX/PICS/WORLD.LBM\",\
maxHumanPlayers = 1,\
difficulty = \"easy\",\
mapFolder = \"<RTTR_GAME>/DATA/MAPS\",\
luaFolder = \"<RTTR_GAME>/CAMPAIGNS/ROMAN\",\
maps = { \"dessert0.WLD\", \"dessert1.WLD\", \"dessert2.WLD\"}\
}\n";
}

// No getRequiredLuaVersion
{
CampaignDescription desc;
CampaignDataLoader loader(desc, tmp);
rttr::test::LogAccessor logAcc;
Expand All @@ -40,41 +54,25 @@ BOOST_AUTO_TEST_CASE(ScriptVersion)

// Correct version
{
rttr::test::TmpFolder tmp;
{
bnw::ofstream file(tmp / "campaign.lua");
file << helpers::format("function getRequiredLuaVersion()\n return %1%\n end",
bnw::ofstream file(campaignFile, std::ios::app);
file << helpers::format("function getRequiredLuaVersion()\n return %1%\n end\n",
CampaignDataLoader::GetVersion());
}

CampaignDescription desc;
CampaignDataLoader loader(desc, tmp);
rttr::test::LogAccessor logAcc;
BOOST_TEST_REQUIRE(!loader.Load());
BOOST_TEST_REQUIRE(loader.Load());
BOOST_TEST(loader.CheckScriptVersion());
logAcc.clearLog();
}

// Backwards compatibility: version 2 can load version 1
{
rttr::test::TmpFolder tmp;
{
bnw::ofstream file(tmp / "campaign.lua");

file << "campaign ={\
version = \"1\",\
author = \"Max Meier\",\
name = \"Meine Kampagne\",\
shortDescription = \"Sehr kurze Beschreibung\",\
longDescription = \"Das ist die lange Beschreibung\",\
image = \"<RTTR_GAME>/GFX/PICS/WORLD.LBM\",\
maxHumanPlayers = 1,\
difficulty = \"easy\",\
mapFolder = \"<RTTR_GAME>/DATA/MAPS\",\
luaFolder = \"<RTTR_GAME>/CAMPAIGNS/ROMAN\",\
maps = { \"dessert0.WLD\", \"dessert1.WLD\", \"dessert2.WLD\"}\
}\
function getRequiredLuaVersion()\n return 1\n end";
bnw::ofstream file(tmp / "campaign.lua", std::ios::app);
file << "function getRequiredLuaVersion()\n return 1\n end\n";
}

CampaignDescription desc;
Expand All @@ -88,14 +86,12 @@ BOOST_AUTO_TEST_CASE(ScriptVersion)

// Wrong version
{
BOOST_TEST_PASSPOINT();
rttr::test::TmpFolder tmp;
BOOST_TEST_PASSPOINT();
{
BOOST_TEST_PASSPOINT();
bnw::ofstream file(tmp / "campaign.lua");
bnw::ofstream file(tmp / "campaign.lua", std::ios::app);
BOOST_TEST_PASSPOINT();
file << helpers::format("function getRequiredLuaVersion()\n return %1%\n end",
file << helpers::format("function getRequiredLuaVersion()\n return %1%\n end\n",
CampaignDataLoader::GetVersion() + 1);
BOOST_TEST_PASSPOINT();
}
Expand Down

0 comments on commit 13a991c

Please sign in to comment.