Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default cwd ignored for google test #87

Closed
csorvagep opened this issue Apr 26, 2019 · 8 comments
Closed

Default cwd ignored for google test #87

csorvagep opened this issue Apr 26, 2019 · 8 comments

Comments

@csorvagep
Copy link

When I modify the default cwd settings and reload the tests, the cwd stays the same. According to the documentation the default cwd value is overwritten by an executable, but there is none set, the list is automatically generated. The project is using google test.

I don't tried to create a specific example to reproduce it, but I assume it is the same for any test. I guess it's because the automatic test discovery.

@matepek
Copy link
Owner

matepek commented Apr 26, 2019

Just tried, it works for me so a decent bug report would be helpful.

@matepek
Copy link
Owner

matepek commented Apr 26, 2019

The cwd has to point to an existing directory

@csorvagep
Copy link
Author

Describe the bug (A clear and concise description of what the bug is.)
After modifying the catch2TestExplorer.defaultCwd the tests are reloading but shows the same directory. I tried it with CMakeTools. I don't know if this is the problem, because it creates the executable inside the build directory.

To Reproduce (Steps to reproduce the behavior:)

  1. CMakeTools - Quick Start - create project
  2. Add to CMakeLists.txt: find_package(GTest MODULE REQUIRED) and target_link_libraries(${PROJECT_NAME} GTest::GTest)
  3. Insert simple test main.cpp:
#include <gtest/gtest.h>
#include <fstream>
#include <iostream>
#include <string>

TEST(cwdTest, fileReadTest)
{
    std::ifstream file("test.txt");
    ASSERT_TRUE(file.good());
    std::string str;
    getline(file, str);
    EXPECT_EQ(str, "asd");
}

int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
  1. Build
  2. Add test.txt with content "asd" next to main.cpp
  3. Run test on Test Explorer, test should fail
  4. Change catch2TestExplorer.defaultCwd to ${workspaceFolder}
  5. Test still fails.

Expected behavior (A clear and concise description of what you expected to happen.)
The directory name next to the test executable should change. (Also inside the tooltip)

Screenshots (If applicable, add screenshots to help explain your problem.)
image

Desktop (please complete the following information):

  • Extension Version 2.4.5
  • CMakeTools Version 1.1.3
  • VS Code Version 1.33.1
  • Google Test Version 1.8.1-2
  • OS Type and Version Windows 10 - 1809

Log (Attach log. (optional, Set: catch2TestExplorer.logfile and reproduce the bug.) Warning: Log probably contains file and test names too.)

The log after changing the setting to ${workspaceFolder} (The user directory is replaced to %userprofile%)

[2019-04-27 12:14:28.832] [INFO] [at TestAdapter.load (%userprofile%.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestAdapter.js:171:19)] load called
[2019-04-27 12:14:28.832] [INFO] [at TestAdapter._getWorkerMaxNumber (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestAdapter.js:391:19)] workerMaxNumber: 1
[2019-04-27 12:14:28.864] [INFO] [at load._mainTaskQueue.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestAdapter.js:177:23)] load started
[2019-04-27 12:14:28.864] [INFO] [at TestAdapter._getExecutables (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestAdapter.js:411:19)] executables: [ { name: '${filename}',
    description: '${relDirpath}/',
    pattern: '{build,Build,BUILD,out,Out,OUT}/**/*{test,Test,TEST}*',
    cwd: '${absDirpath}',
    env: { C2TESTEXECUTABLEPATH: '${absPath}' } } ]
[2019-04-27 12:14:28.864] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:32:26)] pattern { isAbsolute: false,
  absPattern:
   'e:\\code\\cwd_test\\{build,Build,BUILD,out,Out,OUT}\\**\\*{test,Test,TEST}*',
  relativeToWs: '{build,Build,BUILD,out,Out,OUT}\\**\\*{test,Test,TEST}*',
  isPartOfWs: true,
  relativeToWsPosix: '{build,Build,BUILD,out,Out,OUT}/**/*{test,Test,TEST}*' }
[2019-04-27 12:14:28.926] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:62:30)] Checking file for tests: e:\code\cwd_test\build\CTestTestfile.cmake
[2019-04-27 12:14:28.926] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:62:30)] Checking file for tests: e:\code\cwd_test\build\cwd_test.exe
[2019-04-27 12:14:28.926] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:62:30)] Checking file for tests: e:\code\cwd_test\build\CMakeFiles\feature_tests.bin
[2019-04-27 12:14:28.926] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:62:30)] Checking file for tests: e:\code\cwd_test\build\CMakeFiles\feature_tests.c
[2019-04-27 12:14:28.926] [INFO] [at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:62:30)] Checking file for tests: e:\code\cwd_test\build\CMakeFiles\feature_tests.cxx
[2019-04-27 12:14:28.926] [INFO] [at load.suiteCreationAndLoadingTasks.push.c2fs.isNativeExecutableAsync.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:76:34)] Not an executable: e:\code\cwd_test\build\CTestTestfile.cmake [Error: Not a native executable extension on win32: e:\code\cwd_test\build\CTestTestfile.cmake
	at Object.isNativeExecutableAsync (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\FSWrapper.js:91:35)
	at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:63:52)]
[2019-04-27 12:14:28.927] [INFO] [at load.suiteCreationAndLoadingTasks.push.c2fs.isNativeExecutableAsync.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:76:34)] Not an executable: e:\code\cwd_test\build\CMakeFiles\feature_tests.bin [Error: Not a native executable extension on win32: e:\code\cwd_test\build\CMakeFiles\feature_tests.bin
	at Object.isNativeExecutableAsync (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\FSWrapper.js:91:35)
	at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:63:52)]
[2019-04-27 12:14:28.927] [INFO] [at load.suiteCreationAndLoadingTasks.push.c2fs.isNativeExecutableAsync.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:76:34)] Not an executable: e:\code\cwd_test\build\CMakeFiles\feature_tests.c [Error: Not a native executable extension on win32: e:\code\cwd_test\build\CMakeFiles\feature_tests.c
	at Object.isNativeExecutableAsync (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\FSWrapper.js:91:35)
	at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:63:52)]
[2019-04-27 12:14:28.927] [INFO] [at load.suiteCreationAndLoadingTasks.push.c2fs.isNativeExecutableAsync.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:76:34)] Not an executable: e:\code\cwd_test\build\CMakeFiles\feature_tests.cxx [Error: Not a native executable extension on win32: e:\code\cwd_test\build\CMakeFiles\feature_tests.cxx
	at Object.isNativeExecutableAsync (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\FSWrapper.js:91:35)
	at TestExecutableInfo.load (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestExecutableInfo.js:63:52)]
[2019-04-27 12:14:28.970] [INFO] [at GoogleTestSuiteInfo.reloadChildren (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\GoogleTestSuiteInfo.js:26:26)] reloadChildren cwd_test.exe
[2019-04-27 12:14:29.054] [INFO] [at load._mainTaskQueue.then._rootSuite.load.then (%userprofile%\.vscode\extensions\matepek.vscode-catch2-test-adapter-2.4.5\out\src\TestAdapter.js:180:27)] load finished 1

Additional context Add any other context about the problem here.
If I modify the executable name after discovery, the new test does not show up. This might be unrelated.
Also it would be useful to replace variables in catch2TestExplorer.logfile because the VS Code has no rights to write inside ProgramFiles (or defaults to workspace folder).

@matepek
Copy link
Owner

matepek commented Apr 27, 2019

Please insert your settings.json.

@matepek
Copy link
Owner

matepek commented Apr 27, 2019

I got it. I guess, you didn't set the executables variable explicitly. It has a default value which as cwd: '${absDirpath}' specified.

@matepek matepek closed this as completed Apr 27, 2019
@matepek
Copy link
Owner

matepek commented Apr 27, 2019

I will remove that field from the default, it is misleading.

@csorvagep
Copy link
Author

No I didn't set the executables variable. Do you still need my settings.json? I don't thinks there is any related settings except the above described.

@matepek
Copy link
Owner

matepek commented Apr 27, 2019

No, I don't need, thanks. Will release a fix soon, but you can overwrite the "executables" with a value without "cwd" property. That would do the magic too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants