BOOST TEST - minimal ヘッダファイルを使わない新しい単体ファイル形式で利用 ― 2020年05月11日 11時29分51秒
ファイルは boost_included_unit_test.cpp と名付けている。
まずは、少し気を付ける事項から。
// c++ -I /usr/local/include/ boost_included_unit_test.cpp
#include <memory>
#define BOOST_TEST_MODULE VerifyStd
// #include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE( test_shard_ptr )
{
int one = 1;
int two = 3;
BOOST_CHECK( one == 1 );
BOOST_CHECK( two == 2 );
BOOST_CHECK_EQUAL( one, 1 );
BOOST_CHECK_EQUAL( two, 2 );
BOOST_REQUIRE( one == 1 );
BOOST_REQUIRE( two == 2 );
// return 0;
}
- boost/test/unit_test.hpp ではなく boost/test/included/unit_test.hpp を使う。
- BOOST_TEST_MODULE を定義する。
- BOOST_AUTO_TEST_CASE には戻り値は無い。
- main 関数はライブラリが定義し、単一ファイル形式なので -l オプションが必要無い。
これをコンパイルする。
-I はどこに boost ライブラリがインストールされているかに依存する。Linux 系だったら /usr/include 以下で特に必要無いだろう。BSD 系だと /usr/local/include が必要になる。
% c++ -I /usr/local/include/ boost_included_unit_test.cpp
これを実行すると、この様な出力になる。
% c++ -I /usr/local/include/ boost_included_unit_test.cpp
% ./a.out
Running 1 test case...
boost_included_unit_test.cpp(14): error: in "test_shard_ptr": check two == 2 has failed
boost_included_unit_test.cpp(17): error: in "test_shard_ptr": check two == 2 has failed [3 != 2]
boost_included_unit_test.cpp(20): fatal error: in "test_shard_ptr": critical check two == 2 has failed
*** 3 failures are detected in the test module "VerifyStd"
コメント
トラックバック
このエントリのトラックバックURL: http://uyota.asablo.jp/blog/2020/05/11/9245457/tb
※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。
コメントをどうぞ
※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。
※なお、送られたコメントはブログの管理者が確認するまで公開されません。