関連するコードを持っている述語を使用しようとすると、これはUnitTest++/TestRunner.h
からである。ここではunittestの++の問題:状態
class TestRunner
{
public:
explicit TestRunner(TestReporter& reporter);
~TestRunner();
template <class Predicate>
int RunTestsIf(TestList const& list, char const* suiteName,
const Predicate& predicate, int maxTestTimeInMs) const
{
Test* curTest = list.GetHead();
while (curTest != 0)
{
if (IsTestInSuite(curTest,suiteName) && predicate(curTest))
{
RunTest(m_result, curTest, maxTestTimeInMs);
}
curTest = curTest->next;
}
return Finish();
}
private:
TestReporter* m_reporter;
TestResults* m_result;
Timer* m_timer;
int Finish() const;
bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
};
は、私はそれは私がやりたいようにする修正しようとしています私の述語クラスです:
class ListFilterRemember {
char **list;
int n;
Test **testsAlreadyRun;
int index_tar;
int max_allocd;
public:
ListFilterRemember(char **list_, int count) {
int testCount = 0;
Test* curTest = Test::GetTestList().GetHead();
while (curTest != 0) {
testCount++;
}
list = list_; n = count; max_allocd = testCount;
testsAlreadyRun = new Test *[max_allocd];
index_tar = 0;
}
bool operator()(const Test* const t) const {
for (int i=0;i<index_tar;++i) {
if (testsAlreadyRun[i] == t) { return false; }
}
for (int i=0;i<n;++i) {
std::string dot_cpp_appended = std::string(list[i]) + ".cpp";
if (!strcasecmp(t->m_details.testName, list[i]) ||
!strcasecmp(t->m_details.suiteName, list[i]) ||
!strcasecmp(t->m_details.filename, list[i]) ||
!strcasecmp(t->m_details.filename, dot_cpp_appended.c_str()) || (
filename_dir_prefix_len < (int)strlen(t->m_details.filename) && (// ensure the ptr arith in next 2 lines doesn't go out of bounds
!strcasecmp(t->m_details.filename+filename_dir_prefix_len, list[i]) ||
!strcasecmp(t->m_details.filename+filename_dir_prefix_len, dot_cpp_appended.c_str())
)
) || (
std::string::npos != findCaseInsensitive(t->m_details.testName,list[i])
)
) {
// erring on the side of matching more tests
//printf(" running\n");
if (index_tar >= max_allocd) throw std::runtime_error("Did not allocate! Segfault here.");
testsAlreadyRun[index_tar] = (Test *)t;
index_tar += 1;
return true;
}
}
//printf(" not running\n");
return false;
}
~ListFilterRemember() {
delete[] testsAlreadyRun;
}
};
TestRunner.h
に定義されている方法を見ると、operator()
関数がメンバー変数を変更できないようにするconst修飾子が付いています。これらの変更を加えて、すでに実行したテストを覚えて、再度実行しないようにする必要があります。彼らが再び動く危険性がある理由は、私がRunTestsIf()
を何度も実行しようとしているからです。
コマンドラインでテストのリストを入力して、名前に基づいて実行するテストを指定します。これが、文字列にマッチするコードのすべてです。私はまだそれらを使用したいと思いますが、今度は、指定したテストが指定した順序で実行されるように改善したいと思います。これを行うには、テストランナーを移動して、指定されたテストリストを照合し、それらを1つずつ照合します。
アイデア?私はUnitTest ++コードでconstを核にしたいと思っていますが、私がする必要がなければ何かを壊したくありません。
私は 'mutable'キーワードについて知りませんでした。それを指摘してくれてありがとう - それはほぼこのような状況のために作られているかのようです。私はいくつかのテストをして、Predicateで奇妙な動きがあるかどうかを調べる必要がありますが、srcと私が投稿したビットは '' Predicate ''への唯一の参照です。私はUnitTest ++のsrcを少し編集して**動作するようにすることもできますが、おそらく再コンパイルする必要があります。ちょっと...良くない。とりあえずありがとう。 –