简体   繁体   English

VSCode 中的 Gtest,C/C++ 智能感知显示错误

[英]Gtest in VSCode, C/C++ intellisense shows errors

I have an issue, which I guess is caused by the Microsoft C/C++ plugin.我有一个问题,我猜这是由 Microsoft C/C++ 插件引起的。 Intellisense is showing errors at Google Test functions, but there are no actual errors (tests compile and run without any problem). Intellisense 在 Google 测试函数中显示错误,但没有实际错误(测试编译和运行没有任何问题)。

When I hover over the functions with these red error squiggles, it expands to the functionality, F12 (go to definition) works as well.当我用这些红色错误曲线对功能进行 hover 时,它会扩展到功能,F12(转到定义)也可以。

How do I get rid of these intellisense "errors"?如何摆脱这些智能感知“错误”?

I have tried searching for the error messages, for "intellisense Gtest VSCode" and similar, but no luck in finding any useful solution.我已经尝试搜索错误消息,“intellisense Gtest VSCode”和类似的,但没有找到任何有用的解决方案。 My guess is that I missed something, but what?我的猜测是我错过了一些东西,但是什么?

Have also tried playing around with c_cpp_properties.json (tried to include the exact path to gtest, to force include the actual gtest.h file, etc) but no luck there either.还尝试过使用 c_cpp_properties.json (尝试包含 gtest 的确切路径,强制包含实际的 gtest.h 文件等),但也没有运气。

c_cpp_properties.json c_cpp_properties.json

It is pretty simple, basically:这很简单,基本上:

"includePath": [
    "${workspaceFolder}/**"
],

somefile.h一些文件.h

typedef struct {
    unsigned short a;
} myStruct;

somefile.c somefile.c

myStruct s[5];

unsigned short someFunction(void)
{
    // Do stuff
    return s[somePosition].a;
}

test.cpp测试.cpp

#include "gtest/gtest.h"

extern "C" {
    #include "somefile.h"
    extern myStruct s[];
}

TEST(someTest, firstTest)
{
    EXPECT_EQ(s[somePosition].a, someFunction());
}

INSTANTIATE_TEST_CASE_P(someFunction, secondTest,
    testing::Values(
        some_test{ "hello", 0 },
        some_test{ "bye", 1 }
));

VSCode C/C++ intellisense output VSCode C/C++ 智能感知 output

firstTest, error at EXPECT_EQ: firstTest,EXPECT_EQ 处出错:

expression must have bool type (or be convertible to bool)C/C++(711)

secondTest, error at INSTANTIATE_TEST_CASE_P: secondTest,在 INSTANTIATE_TEST_CASE_P 处出错:

namespace "std" has no member "string"C/C++(135)

Solved it by editing c_cpp_properties.json :通过编辑c_cpp_properties.json解决了它:

"includePath": [
    "${workspaceFolder}/**",
    "${workspaceFolder}/Tests/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/**"
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM