Create  Edit  Diff  FrontPage  Index  Search  Changes  History  RSS  Source  Login

SpecForC++

概要

C++でRSpec*1っぽいテストを書くためのツールの試作版です。

現時点で、次のようなテストが書けます。

サンプル

DESCRIBE("int_vector")
{
    std::vector<int> *v;
    BEFORE{
        v=new std::vector<int>;
    }
    AFTER{
        delete v;
    }

    VERIFY{
        THAT{
            IT(v->empty())
                SHOULD(BE_TRUE);
            v->push_back(1);
            IT(v->at(0))SHOULD(==1);
        }

        AND_THAT{
            IT(v->empty())
                SHOULD(BE_TRUE);
            v->push_back(2);
            IT(v->at(0))SHOULD(==3);
        }
        OVER;
    }
} END_DESCRIBE;

DESCRIBE("int")
{
    VERIFY{
        THAT{
            IT(1+1)SHOULD(==2);
            IT(2*3)SHOULD(==6);
            IT(1/2)SHOULD(==0.5);
        }
        AND_THAT{
            IT(!)SHOULD("This is executed and be failed");
        }
        AND_THAT{
            IT(!)SHOULD("...and this is executed too and be failed");
        }
        OVER
    }
} END_DESCRIBE;

全ソース

実行結果

//// int_vector ////
Test(135) OK : v->empty()BE_TRUE
Test(138) OK : v->at(0)==1
Test(142) OK : v->empty()BE_TRUE
Test(145) NG : v->at(0)==3
//// int ////
Test(155) OK : 1+1==2
Test(156) OK : 2*3==6
Test(157) NG : 1/2==0.5
Test(160) NG : !"This is executed and be failed"
Test(163) NG : !"...and this is executed too and be failed"
Last modified:2008/07/11 23:53:42
Keyword(s):
References: