我只是在尝试我的教程来尝试 catch2 单元测试库。我在 10.14 中使用 mac。我没有完整的 XCode,只有 cmd 工具和 macports 在我的设置中运行完美(没有 brew)。我按照建议使用合并的单个头文件和源文件。
然而,一个简单的教程:
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
给出了许多编译错误 - snip:
In file included from test1.cpp:2:
./catch.hpp:75:49: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
NonCopyable( NonCopyable const& ) = delete;
^
./catch.hpp:76:37: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
NonCopyable( NonCopyable&& ) = delete;
^
./catch.hpp:76:44: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
NonCopyable( NonCopyable&& ) = delete;
^
./catch.hpp:77:60: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
NonCopyable& operator=( NonCopyable const& ) = delete;
^
./catch.hpp:78:48: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
NonCopyable& operator=( NonCopyable&& ) = delete;
^
./catch.hpp:78:55: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
NonCopyable& operator=( NonCopyable&& ) = delete;
^
./catch.hpp:81:26: error: expected ';' at end of declaration list
NonCopyable() noexcept = default;
^
;
请建议,谢谢。
编辑:
在@Tiib 建议尝试g++ -std=c++17
编译和构建代码之后。g++ -std=c++11
也没有工作。不明白为什么。