icinga2/test/test-ctest.hpp

67 lines
1.7 KiB
C++
Raw Permalink Normal View History

Replace all existing copyright headers with `SPDX` headers I've used the following command to replace the original copyright header lines in a C-style comment block: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` For files that use shell-style comments (#) like CMakeLists.txt, I've used this command: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` And for SQL files: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ```
2026-01-27 09:06:40 -05:00
// SPDX-FileCopyrightText: 2025 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <BoostTestTargetConfig.h>
#include <boost/filesystem/path.hpp>
#include <boost/test/tree/traverse.hpp>
#include <fstream>
namespace icinga {
class CTestPropertiesBase : public boost::unit_test::decorator::base
{
public:
virtual std::string Get() = 0;
};
/**
* A boost test decorator to set additional ctest properties for the test.
*/
class CTestProperties : public CTestPropertiesBase
{
public:
explicit CTestProperties(std::string props) : m_Props(std::move(props)) {}
std::string Get() override { return m_Props; }
private:
std::string m_Props;
/**
* Doesn't do anything to the case/suite it's applied to.
*
* However this gets added to the list so we can later find it by iterating the
* decorators and dynamic_casting them to this type and get the m_props value.
*/
void apply(boost::unit_test::test_unit&) override {}
[[nodiscard]] boost::unit_test::decorator::base_ptr clone() const override;
};
class CTestFileGenerator : public boost::unit_test::test_tree_visitor
{
public:
CTestFileGenerator(const boost::filesystem::path& testexe, const boost::filesystem::path& outfile);
void visit(const boost::unit_test::test_case& test) override;
bool test_suite_start(const boost::unit_test::test_suite& suite) override;
void test_suite_finish(const boost::unit_test::test_suite& suite) override;
private:
static std::string LabelsToProp(const std::vector<std::string>& labels);
std::ofstream m_Fp;
boost::filesystem::path m_WorkDir;
boost::filesystem::path m_TestExe;
std::vector<std::vector<std::string>> m_PropsStack;
};
struct CTestFileGeneratorFixture
{
CTestFileGeneratorFixture();
};
} // namespace icinga