Browse Source

Skip tests gracefully without MPQ assets

pull/8280/head
Leslie P. Polzer 4 months ago committed by Anders Jenbo
parent
commit
b76f906ddc
  1. 17
      test/inv_test.cpp
  2. 79
      test/main.cpp
  3. 18
      test/pack_test.cpp
  4. 9
      test/player_test.cpp
  5. 5
      test/timedemo_test.cpp
  6. 15
      test/vendor_test.cpp
  7. 5
      test/writehero_test.cpp

17
test/inv_test.cpp

@ -9,12 +9,17 @@
namespace devilution { namespace devilution {
namespace { namespace {
constexpr const char MissingMpqAssetsSkipReason[] = "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test suite";
class InvTest : public ::testing::Test { class InvTest : public ::testing::Test {
public: public:
void SetUp() override void SetUp() override
{ {
Players.resize(1); Players.resize(1);
MyPlayer = &Players[0]; MyPlayer = &Players[0];
if (missingMpqAssets_) {
GTEST_SKIP() << MissingMpqAssetsSkipReason;
}
} }
static void SetUpTestSuite() static void SetUpTestSuite()
@ -22,16 +27,22 @@ public:
LoadCoreArchives(); LoadCoreArchives();
LoadGameArchives(); LoadGameArchives();
// The tests need spawn.mpq or diabdat.mpq missingMpqAssets_ = !HaveMainData();
// Please provide them so that the tests can run successfully if (missingMpqAssets_) {
ASSERT_TRUE(HaveMainData()); return;
}
InitCursor(); InitCursor();
LoadSpellData(); LoadSpellData();
LoadItemData(); LoadItemData();
} }
private:
static bool missingMpqAssets_;
}; };
bool InvTest::missingMpqAssets_ = false;
/* Set up a given item as a spell scroll, allowing for its usage. */ /* Set up a given item as a spell scroll, allowing for its usage. */
void set_up_scroll(Item &item, SpellID spell) void set_up_scroll(Item &item, SpellID spell)
{ {

79
test/main.cpp

@ -1,9 +1,83 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream>
#include <string>
#include <unordered_map>
#include "headless_mode.hpp" #include "headless_mode.hpp"
#include "options.h" #include "options.h"
#include "utils/paths.h" #include "utils/paths.h"
namespace {
// Custom listener to track and report skipped tests with reasons
class SkippedTestListener : public testing::EmptyTestEventListener {
std::unordered_map<std::string, int> skipReasons;
int totalSkipped = 0;
void OnTestPartResult(const testing::TestPartResult &test_part_result) override
{
if (test_part_result.skipped()) {
totalSkipped++;
std::string reason = test_part_result.message();
if (reason.empty()) {
reason = "No reason provided";
}
skipReasons[reason]++;
}
}
void OnTestProgramEnd(const testing::UnitTest & /*unit_test*/) override
{
if (totalSkipped > 0) {
std::cout << "\n";
std::cout << "========================================\n";
std::cout << "Test Skip Summary\n";
std::cout << "========================================\n";
std::cout << "Total tests skipped: " << totalSkipped << "\n\n";
// Show skip reasons, with most specific reasons first
bool hasMpqReason = false;
bool hasNoReason = false;
int mpqSkipCount = 0;
int noReasonCount = 0;
for (const auto &[reason, count] : skipReasons) {
if (reason.find("MPQ assets") != std::string::npos) {
hasMpqReason = true;
mpqSkipCount += count;
continue;
}
if (reason == "No reason provided") {
hasNoReason = true;
noReasonCount += count;
continue;
}
std::cout << "" << count << " test" << (count > 1 ? "s" : "") << " skipped: " << reason << "\n";
}
// Combine MPQ-related skips for clearer output
if (hasMpqReason) {
int totalMpqRelated = mpqSkipCount + (hasNoReason ? noReasonCount : 0);
std::cout << "" << totalMpqRelated << " test" << (totalMpqRelated > 1 ? "s" : "")
<< " skipped: MPQ assets (spawn.mpq or DIABDAT.MPQ) not found\n";
if (hasNoReason && noReasonCount > 0) {
std::cout << " (" << noReasonCount << " test" << (noReasonCount > 1 ? "s" : "")
<< " automatically skipped due to test suite setup failure)\n";
}
} else if (hasNoReason) {
// Only "No reason provided" - show it as-is
std::cout << "" << noReasonCount << " test" << (noReasonCount > 1 ? "s" : "")
<< " skipped: " << "No reason provided" << "\n";
}
std::cout << "========================================\n";
}
}
};
} // namespace
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// Disable error dialogs. // Disable error dialogs.
@ -20,5 +94,10 @@ int main(int argc, char **argv)
#endif #endif
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
// Add custom listener to track and report skipped tests
testing::TestEventListeners &listeners = testing::UnitTest::GetInstance()->listeners();
listeners.Append(new SkippedTestListener());
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

18
test/pack_test.cpp

@ -15,6 +15,8 @@
namespace devilution { namespace devilution {
namespace { namespace {
constexpr const char MissingMpqAssetsSkipReason[] = "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test suite";
void SwapLE(ItemPack &pack) void SwapLE(ItemPack &pack)
{ {
pack.iSeed = Swap32LE(pack.iSeed); pack.iSeed = Swap32LE(pack.iSeed);
@ -894,6 +896,10 @@ class NetPackTest : public ::testing::Test {
public: public:
void SetUp() override void SetUp() override
{ {
if (missingMpqAssets_) {
GTEST_SKIP() << MissingMpqAssetsSkipReason;
}
Players.resize(2); Players.resize(2);
MyPlayer = &Players[0]; MyPlayer = &Players[0];
gbIsMultiplayer = true; gbIsMultiplayer = true;
@ -976,9 +982,10 @@ public:
LoadCoreArchives(); LoadCoreArchives();
LoadGameArchives(); LoadGameArchives();
// The tests need spawn.mpq or diabdat.mpq missingMpqAssets_ = !HaveMainData();
// Please provide them so that the tests can run successfully if (missingMpqAssets_) {
ASSERT_TRUE(HaveMainData()); return;
}
SetHellfireState(false); SetHellfireState(false);
InitCursor(); InitCursor();
@ -987,8 +994,13 @@ public:
LoadMonsterData(); LoadMonsterData();
LoadItemData(); LoadItemData();
} }
private:
static bool missingMpqAssets_;
}; };
bool NetPackTest::missingMpqAssets_ = false;
bool TestNetPackValidation() bool TestNetPackValidation()
{ {
PlayerNetPack packed; PlayerNetPack packed;

9
test/player_test.cpp

@ -86,7 +86,9 @@ TEST(Player, PM_DoGotHit)
{ {
LoadCoreArchives(); LoadCoreArchives();
LoadGameArchives(); LoadGameArchives();
ASSERT_TRUE(HaveMainData()); if (!HaveMainData()) {
GTEST_SKIP() << "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test";
}
LoadPlayerDataFiles(); LoadPlayerDataFiles();
Players.resize(1); Players.resize(1);
@ -191,8 +193,9 @@ TEST(Player, CreatePlayer)
LoadGameArchives(); LoadGameArchives();
// The tests need spawn.mpq or diabdat.mpq // The tests need spawn.mpq or diabdat.mpq
// Please provide them so that the tests can run successfully if (!HaveMainData()) {
ASSERT_TRUE(HaveMainData()); GTEST_SKIP() << "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test";
}
LoadPlayerDataFiles(); LoadPlayerDataFiles();
LoadMonsterData(); LoadMonsterData();

5
test/timedemo_test.cpp

@ -48,8 +48,9 @@ void RunTimedemo(std::string timedemoFolderName)
LoadGameArchives(); LoadGameArchives();
// The tests need spawn.mpq or diabdat.mpq // The tests need spawn.mpq or diabdat.mpq
// Please provide them so that the tests can run successfully if (!HaveMainData()) {
ASSERT_TRUE(HaveMainData()); GTEST_SKIP() << "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test";
}
const std::string unitTestFolderCompletePath = paths::BasePath() + "test/fixtures/timedemo/" + timedemoFolderName; const std::string unitTestFolderCompletePath = paths::BasePath() + "test/fixtures/timedemo/" + timedemoFolderName;
paths::SetPrefPath(unitTestFolderCompletePath); paths::SetPrefPath(unitTestFolderCompletePath);

15
test/vendor_test.cpp

@ -16,6 +16,7 @@ using ::testing::AnyOf;
using ::testing::Eq; using ::testing::Eq;
constexpr int SEED = 75357; constexpr int SEED = 75357;
constexpr const char MissingMpqAssetsSkipReason[] = "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test suite";
std::string itemtype_str(ItemType type); std::string itemtype_str(ItemType type);
std::string misctype_str(item_misc_id type); std::string misctype_str(item_misc_id type);
@ -78,6 +79,10 @@ class VendorTest : public ::testing::Test {
public: public:
void SetUp() override void SetUp() override
{ {
if (missingMpqAssets_) {
GTEST_SKIP() << MissingMpqAssetsSkipReason;
}
Players.resize(1); Players.resize(1);
MyPlayer = &Players[0]; MyPlayer = &Players[0];
gbIsHellfire = false; gbIsHellfire = false;
@ -90,13 +95,21 @@ public:
{ {
LoadCoreArchives(); LoadCoreArchives();
LoadGameArchives(); LoadGameArchives();
ASSERT_TRUE(HaveMainData()); missingMpqAssets_ = !HaveMainData();
if (missingMpqAssets_) {
return;
}
LoadPlayerDataFiles(); LoadPlayerDataFiles();
LoadItemData(); LoadItemData();
LoadSpellData(); LoadSpellData();
} }
private:
static bool missingMpqAssets_;
}; };
bool VendorTest::missingMpqAssets_ = false;
std::string itemtype_str(ItemType type) std::string itemtype_str(ItemType type)
{ {
const std::string ITEM_TYPES[] = { const std::string ITEM_TYPES[] = {

5
test/writehero_test.cpp

@ -368,8 +368,9 @@ TEST(Writehero, pfile_write_hero)
LoadGameArchives(); LoadGameArchives();
// The tests need spawn.mpq or diabdat.mpq // The tests need spawn.mpq or diabdat.mpq
// Please provide them so that the tests can run successfully if (!HaveMainData()) {
ASSERT_TRUE(HaveMainData()); GTEST_SKIP() << "MPQ assets (spawn.mpq or DIABDAT.MPQ) not found - skipping test";
}
const std::string savePath = paths::BasePath() + "multi_0.sv"; const std::string savePath = paths::BasePath() + "multi_0.sv";
paths::SetPrefPath(paths::BasePath()); paths::SetPrefPath(paths::BasePath());

Loading…
Cancel
Save