The only way that I found not to execute a test was not to register it in CPPUnit. FilterTest() does this by replacing a valid test or test group with a dummy one, SkipTest, which just prints the test name and that it is skipped. Registering tests has to be intercepted at multiple levels: - CPPUNIT_TEST in test suites - ADD_TEST in ClientTest - addTest in ClientTest Not currently intercepted are complete test suites (CPPUNIT_TEST_SUITE). The main purpose of this patch is to avoid running the time consuming suspend and interrupt tests, but this feature might also be useful for other tests, which is why it was implemented in a more general way.
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
/*
|
|
* Copyright (C) 2009 Intel Corporation
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) version 3.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301 USA
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include <config.h>
|
|
#endif
|
|
|
|
#if defined(ENABLE_INTEGRATION_TESTS) || defined(ENABLE_UNIT_TESTS)
|
|
|
|
#include "test.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <iostream>
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
class SkipTest : public CppUnit::TestCase {
|
|
public:
|
|
SkipTest(const std::string &name) :
|
|
TestCase(name)
|
|
{}
|
|
void run (CppUnit::TestResult *result) {
|
|
std::cerr << getName() << " *** skipped ***\n";
|
|
}
|
|
};
|
|
|
|
CppUnit::Test *FilterTest(CppUnit::Test *test)
|
|
{
|
|
static std::set<std::string> filter;
|
|
static bool filterValid;
|
|
|
|
if (!filterValid) {
|
|
const char *str = getenv("CLIENT_TEST_SKIP");
|
|
if (str) {
|
|
boost::split(filter, str, boost::is_any_of(","));
|
|
}
|
|
filterValid = true;
|
|
}
|
|
|
|
std::string name = test->getName();
|
|
if (filter.find(name) != filter.end()) {
|
|
delete test;
|
|
return new SkipTest(name);
|
|
} else {
|
|
return test;
|
|
}
|
|
}
|
|
|
|
#endif
|