crpcut (pronounced "crap cut") is the Compartmented Robust Posix C++ Unit Tester. It's super handy for writing tests that other unit-test frameworks just can't handle.
Let’s look at a quick example of testing parts of std::string
:
#include < crpcut.hpp >
#include < string >
This is a simple structure for most tests:
struct apastr // fixture for most tests
{
apastr() : s("apa") {}
std::string s;
};
You can group similar tests into test suites. Here’s how you might set up some basic tests:
TESTSUITE(basics)
{
TEST(default_constr_and_destr)
{
std::string s;
ASSERT_TRUE(s.empty());
ASSERT_EQ(s.length(), 0);
}
TEST(constr_from_char_array, apastr,
depends_on(default_constr_and_destr))
{
ASSERT_EQ(s.length(), 3UL);
}TEST(at, apastr,
depends_on(default_constr_and_destr))
{
ASSERT_EQ(s.at(1), 'p');
}
If something goes wrong, crpcut makes it easy to catch errors. You can set your expectations and check them easily.
TESTSUITE(errors, DEPENDS_ON(ALL_TESTS(basics))) { ... }
A cool feature is that each test runs in its own process and has its own working directory. This means if one test fails, it won’t mess with the others. It really helps keep things clean!
The suite will keep running even if one test crashes. You can also set time limits on tests; if they take too long, crpcut will stop them automatically!
The main process doesn’t use dynamic memory when starting a test case. So if you're using tools like valgrind, you'll catch any memory leaks easily.
If your computer has multiple cores, crpcut lets you run several test cases at once! This can save you time.
If there are files left over after a test finishes, that test is marked as failed. The working directory stays untouched so you can check it out later.
Go to the Softpas website, press the 'Downloads' button, and pick the app you want to download and install—easy and fast!
SoftPas is your platform for the latest software and technology news, reviews, and guides. Stay up to date with cutting-edge trends in tech and software development.
Subscribe to newsletter
© Copyright 2024, SoftPas, All Rights Reserved.