Skip to content

TsukiNi22/ai-utils / skills/tests/cpp-tests

cpp-tests

Unverified

FileKindSize
SKILL.mdskill md7.3 KB
requires.txtmarkdown64 B
scripts/untested.pyexecutablescript7.4 KB
templates/Module.cppother2.7 KB
templates/tools/StepSynchronizer.hppother2.3 KB
templates/tools/TempDir.hppother3.5 KB

templates/Module.cpp

View on GitHub
{{HEADER}}

#include "{{INCLUDE}}"
#include <gtest/gtest.h>
#include <unistd.h>
#include <cstdlib>
#include <ostream>
#include <string>

/* ------------------------------- {{CLASS}} ------------------------------- */
TEST({{CLASS}}, DefaultState) {
    {{NAMESPACE}}::{{CLASS}} object;
    EXPECT_EQ(object.size(), 0u);
}

TEST({{CLASS}}, Nominal) {
    {{NAMESPACE}}::{{CLASS}} object;
    ASSERT_NO_THROW(object.add("value"));
    EXPECT_EQ(object.size(), 1u);
}

TEST({{CLASS}}, UnknownIdThrows) {
    {{NAMESPACE}}::{{CLASS}} object;
    try {
        object.remove(42);
        FAIL() << "Expected an exception";
    } catch (const utils::exception::IException& e) {
        EXPECT_EQ(e.getCode(), utils::exception::InternalCode::UnknownId);
    }
}

/* ------------------------------- Fixture --------------------------------- */
class {{CLASS}}Test : public ::testing::Test {
    protected:
        {{NAMESPACE}}::{{CLASS}} _object;

        void SetUp(void) override {this->_object.add("first");}; // shared starting state
        void TearDown(void) override {}; // reset any global state touched by the tests
};

TEST_F({{CLASS}}Test, KeepsExistingValues) {
    this->_object.add("second");
    EXPECT_EQ(this->_object.size(), 2u);
}

/* ------------------------------ Parametrized ----------------------------- */
struct {{CLASS}}Case {
    std::string input;
    bool valid;
};
std::ostream& operator<<(std::ostream& os, const {{CLASS}}Case& c) {return os << '"' << c.input << '"';}

class {{CLASS}}Validation : public ::testing::TestWithParam<{{CLASS}}Case> {};

TEST_P({{CLASS}}Validation, Input) {
    {{NAMESPACE}}::{{CLASS}} object;
    EXPECT_EQ(object.check(GetParam().input), GetParam().valid);
}

INSTANTIATE_TEST_SUITE_P(Cases, {{CLASS}}Validation,
    ::testing::Values(
        {{CLASS}}Case{"value", true},
        {{CLASS}}Case{"", false}
    )
);

/* ----------------------------- Isolated cases ---------------------------- */
// Run the scenario in a sub-process with a timeout: a hang (or crash) is reported as a failure
#define ISOLATED(...) EXPECT_EXIT({::alarm(10); __VA_ARGS__; std::exit(::testing::Test::HasFailure() ? 1 : 0);}, ::testing::ExitedWithCode(0), "")

static void DestructionDuringWorkScenario(void)
{
    {{NAMESPACE}}::{{CLASS}} object;
    object.start();
    EXPECT_TRUE(object.running());
}
TEST({{CLASS}}, DestructionDuringWork) {ISOLATED(DestructionDuringWorkScenario());}

/* ------------------------------ Known bugs ------------------------------- */
// Expected behavior: fails until the bug is fixed in the sources (never changed to make the test pass)
TEST({{CLASS}}, ClearKeepsCapacity) {
    {{NAMESPACE}}::{{CLASS}} object;
    object.add("value");
    object.clear();
    EXPECT_EQ(object.size(), 0u);
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 318kUpdated Claude CodeCodexUnverifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 318kUpdated Claude CodeCodexUnverifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 318kUpdated Claude CodeCodexUnverifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall