Kann ich programmatisch boost_auto_test_case erstellen?C++

Programme in C++. Entwicklerforum
Anonymous
 Kann ich programmatisch boost_auto_test_case erstellen?

Post by Anonymous »

Ich habe ein Testprojekt, das mehrere verschiedene Dateien aufnimmt und den Inhalt analysiert Aber ich möchte in der Lage sein, jeden einzeln einzeln auszuführen, wenn möglich, aber die AI -Agenten scheitern mich in diesem Fall. Ich würde es vorziehen, die Kompatibilität mit Boost 1.63 zu halten, da Kunden, die Probleme mit der Upgrade von Software -Versionen haben

Code: Select all

#include 
#include 

#include "Helpers/MyTestHelper.h"

#include "Utils/ExceptionHandler.h"

namespace MyProjecNamespace
{
/// Test Fixture
struct MyProjectScriptFixture
{
boost::filesystem::path testDir_; ///< File path to the Project scripts directory

MyProjectScriptFixture()
: testDir_(boost::filesystem::system_complete("Scripts"))
{
SetupFloatingPointEnvironment();
}

~MyProjectScriptFixture() {}
};

BOOST_FIXTURE_TEST_SUITE(MyProjectScriptTests, MyProjectScriptFixture)

BOOST_AUTO_TEST_CASE(RunMyProject_TestSuite)
{
boost::filesystem::recursive_directory_iterator it(testDir_);
boost::filesystem::recursive_directory_iterator end;

while (it != end)
{
if (boost::filesystem::is_regular_file(it->path()))
{
InputProcessor inputProcessor(FileParsingOptions{ false, true, false, true, false });

inputProcessor.DisableLogging();
inputProcessor.ProcessFileInput(it->path().generic_string());

std::pair result - inputProcessor.GetVerificationStatus();

BOOST_CHECK_MESSAGE(result.first, it->path().filename().string() + " - " + result.second);
}
++it:
}
}

BOOST_AUTO_TEST_SUITE_END()
}
< /code>
Und hier ist das, was der GPT vorschlug, aber Visual Studio und Boost waren nicht zufrieden mit < /p>
#include 
#include 
#include 
#include 
#include  // For std::replace

#include "Helpers/MyTestHelper.h"
#include "Utils/ExceptionHandler.h"

namespace MyProjecNamespace
{
/// Test Fixture
struct MyProjectScriptFixture
{
boost::filesystem::path testDir_; ///< File path to the Project scripts directory

MyProjectScriptFixture()
: testDir_(boost::filesystem::system_complete("Scripts"))
{
SetupFloatingPointEnvironment();
}

~MyProjectScriptFixture() {}
};

// Function to create a test case for a specific file
void CreateTestForFile(const boost::filesystem::path& filePath)
{
// Create a unique test case name based on the relative path
std::string relativePath = filePath.parent_path().string();
std::string testName = relativePath + "/" + filePath.stem().string(); // Include directory in the name

// Replace slashes with underscores for valid C++ identifiers
std::replace(testName.begin(), testName.end(), '/', '_');
std::replace(testName.begin(), testName.end(), '\\', '_'); // Handle Windows paths

// Create a unique test case for each file
BOOST_AUTO_TEST_CASE(test_case_##testName)
{
InputProcessor inputProcessor(FileParsingOptions{ false, true, false, true, false });
inputProcessor.DisableLogging();
inputProcessor.ProcessFileInput(filePath.generic_string());

std::pair result = inputProcessor.GetVerificationStatus();
BOOST_CHECK_MESSAGE(result.first, filePath.filename().string() + " - " + result.second);
}
}

BOOST_AUTO_TEST_SUITE(MyProjectScriptTests, MyProjectScriptFixture)

BOOST_AUTO_TEST_CASE(DiscoverAndRunTests)
{
boost::filesystem::recursive_directory_iterator it(testDir_);
boost::filesystem::recursive_directory_iterator end;

while (it != end)
{
if (boost::filesystem::is_regular_file(it->path()))
{
CreateTestForFile(it->path());
}
++it;
}
}

BOOST_AUTO_TEST_SUITE_END()
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post