Могу ли я программно создать BOOST_AUTO_TEST_CASEC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Могу ли я программно создать BOOST_AUTO_TEST_CASE

Сообщение Anonymous »

У меня есть тестовый проект, который принимает множество различных файлов и анализирует содержимое, чтобы стимулировать различные части моей библиотеки C ++, а затем создает объект проверки, который у меня в настоящее время есть один пример теста Boost, который проходит через все мои сценарии и работает нормально Но я хотел бы иметь возможность запустить каждый из них по отдельности, если это возможно, но агенты ИИ подводят меня в этом. Я бы предпочел сохранить совместимость с Boost 1.63 из -за клиентов, у которых есть проблемы с обновлением программного обеспечения < /p>
Вот моя текущая настройка < /p>
#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>
И вот что предполагал GPT, но Visual Studio и Boost не были довольны < /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()
}


Подробнее здесь: https://stackoverflow.com/questions/794 ... test-cases
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»