【发布时间】:2021-02-09 03:20:07
【问题描述】:
我正在使用 googleTest 测试 C 代码。 我的 test.cpp 文件是这样的
#include <gtest/gtest.h>
extern "C" {
#include "list.h"
#include "list.c"
}
TEST(ListTest, singleInsertion) {
// some tests
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
但是尝试使用从终端运行测试
g++ test.cpp -lgtest 给出错误和警告,好像正在测试的代码是 C++ 而不是 C。
错误和警告示例:
error: invalid conversion for mallocs 和
warning: ISO C++ forbids converting a string constant to ‘char*'
如何声明我的测试文件是 C 而不是 C++?
【问题讨论】:
-
强烈建议:不要这样做:
#include "list.c",而是为list.c创建一个头文件,然后更正你的编译和链接语句
标签: c++ c unit-testing testing googletest