[英]GoogleTest `expression result unused'
EDIT: per @πάνταῥεῖ feedback, I am editing the question. 编辑:根据@πάνταῥεῖ反馈,我正在编辑问题。
Using googletest framework to do parameterized test. 使用googletest框架进行参数化测试。 For the following line I am getting warnings:
对于以下行,我收到警告:
clang++ -isystem ../include -g -Wall -Wextra -pthread -std=c++03 -Wno-unknown-pragmas -Wno-missing-field-initializers -c ../samples/sample7_unittest.cc
../samples/sample7_unittest.cc:15:62: warning: expression result unused [-Wunused-value]
INSTANTIATE_TEST_CASE_P(SomeName, MyTest, ::testing::Values((1, 2)));
^
../include/gtest/gtest-param-test.h:1423:66: note: expanded from macro 'INSTANTIATE_TEST_CASE_P'
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
^
1 warning generated.
Below is my code, I used the sample7 as starting point 下面是我的代码,我使用sample7作为起点
#include "gtest/gtest.h"
using ::testing::TestWithParam;
class MyTest : public TestWithParam<int> {
public:
virtual void SetUp() { ch = GetParam(); }
int ch;
};
TEST_P(MyTest, foo) {
EXPECT_EQ(ch, 10);
}
INSTANTIATE_TEST_CASE_P(SomeName, MyTest, ::testing::Values((1, 2)));
Below is my makefile: 下面是我的makefile:
CXX=clang++
GTEST_DIR = ..
USER_DIR = ../samples
CPPFLAGS += -isystem $(GTEST_DIR)/include
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++03 -Wno-unknown-pragmas -Wno-missing-field-initializers
TESTS = sample7_unittest
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h $(GTEST_DIR)/include/gtest/internal/*.h
all : $(TESTS)
clean :
rm -f $(TESTS) gtest.a gtest_main.a *.o
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
gtest-all.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc
gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^
gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^
sample7_unittest.o : $(USER_DIR)/sample7_unittest.cc $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample7_unittest.cc
sample7_unittest : sample7_unittest.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
I am using LLVM 3.7.1 compiler. 我正在使用LLVM 3.7.1编译器。 The issues is the
-std=c++03
flag, without the flag I am not getting the warning. 问题是
-std=c++03
标志,没有该标志我没有得到警告。 Anything I can do to eliminate it? 我可以采取什么措施消除它? It looks bad on regression test logs.
在回归测试日志上看起来很糟糕。
Note: I also added an issue here: https://github.com/google/googletest/issues/755 注意:我还在这里添加了一个问题: https : //github.com/google/googletest/issues/755
There is an surplus pair of parentheses in: 在下面有一对多余的括号:
INSTANTIATE_TEST_CASE_P(SomeName, MyTest, ::testing::Values((1, 2)));
Replace with: 用。。。来代替:
INSTANTIATE_TEST_CASE_P(SomeName, MyTest, ::testing::Values(1, 2));
to remove the warning. 删除警告。
I find the presence or absence of -std-c++03
to be immaterial (clang++3.7, g++ 5.2). 我发现
-std-c++03
的存在与否无关紧要(clang ++ 3.7,g ++ 5.2)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.