Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CppUTest を試してみた

CppUTest を試してみた

C++勉強会 in 広島 での LT 資料
http://partake.in/events/5ddde1fe-88b7-4541-9f37-02cf4fa0284c

C++の勉強会だし、オープンセミナー2014@広島の告知をしないとだし、ということでC++のテスティングフレームワークを試した。

解説とかはこちらに
http://blog.eiel.info/blog/2014/01/11/cpp-hiroshima/
コードはこちらに。
https://github.com/eiel/cpphiroshima-1

Tomohiko Himura

January 10, 2014
Tweet

More Decks by Tomohiko Himura

Other Decks in Programming

Transcript

  1. ؀ڥ $ clang++ -v apple LLVM version 5.0 (clang-500.2.79) (based

    on LLVM 3.3svn) Target: x86_64-apple-darwin13.0.0 Thread model: posix
  2. ςετίʔυ #include "CppUTest/TestHarness.h" TEST_GROUP(TMP) { }; ! TEST(TMP, factorial_2) {

    CHECK_EQUAL(2, factorial < 2 >::value); } ! TEST(TMP, factorial_3) { CHECK_EQUAL(6, factorial < 3 >::value); } ظ଴͢Δ݁Ռ 2! ظ଴͢Δ݁Ռ 3! άϧʔϓ໊ ςετ໊ άϧʔϓ໊
  3. ςετϥϯφʔ #include "CppUTest/CommandLineTestRunner.h" ! int main(int ac, char** av) {

    return CommandLineTestRunner::RunAllTests(ac, av); } ! IMPORT_TEST_GROUP(TMP); άϧʔϓ໊
  4. ࣮ߦͯ͠ΈΔ src/factorial_test.cpp:15:18: error: use of undeclared identifier 'factorial' CHECK_EQUAL(2, factorial

    < 2 >::value); ^ /usr/local/include/CppUTest/UtestMacros.h:116:34: note: expanded from macro 'CHECK_EQUAL' CHECK_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__) ^ /usr/local/include/CppUTest/UtestMacros.h:119:60: note: expanded from macro 'CHECK_EQUAL_LOCATION' { UtestShell::getCurrent()->assertEquals(((expected) != (actual)), Str... ^ src/factorial_test.cpp:15:35: error: no member named 'value' in the global namespace CHECK_EQUAL(2, factorial < 2 >::value); ~~^
  5. ࣮૷ͯ͠Έͨ template < unsigned N > struct factorial { static

    constexpr unsigned value = N * factorial < N - 1 >::value; }; ! template < > struct factorial < 0 > { static constexpr unsigned value = 1; };
  6. Θ͟ͱࣦഊͤͯ͞ΈΑ͏ template < > struct factorial < 0 > {

    static constexpr unsigned value = 4; };
  7. ࣮ߦ݁Ռ src/factorial_test.cpp:31: error: Failure in TEST(TMP, factorial_3) expected <6> but

    was < 24 (0x00000018)> difference starts at position 0 at: < 24>
  8. TUBUJD@BTTFSU static_assert(2 == factorial < 2 >::value, "should factorial(2) ==

    2"); static_assert(3*2 == factorial < 3 >::value, "should factorial(3) == 6");