Shatur / neovim-cmake

CMake integration for Neovim
GNU General Public License v3.0
87 stars 19 forks source link

Upon coredump (crash) plugin reports 0 return #28

Closed shrkamat closed 2 years ago

shrkamat commented 2 years ago

Bug description Upon coredump (crash) plugin reports 0 return. It's easily misinterpreted for run step to be success.

Steps to reproduce

git clone git@github.com:shrkamat/NvimCMakePluginTest.git
cd NvimCMakePluginTest
vim test.cpp
:CMake configure
:CMake build_and_run
Minimal configuration

Expected behavior Should report non-zero value upon failure and crash.

Screenshots CMake build_and_run, reports success for crashed processes

Environment

Shatur commented 2 years ago

Thanks for the report! I noticed that it works correctly (exists with code 1) if I comment out this part:

TEST(NvimCMakePlugin, ReportsFailedTestCorrectly) {
    int divisor = 0;
    ASSERT_EQ(10, 100/divisor);
}

The following program is also exits with the expected exit code:

int main()
{
    return 1;
}

I use exit codes that returned by Plenary.Job, so I assume that it's an upstream issue.

Shatur commented 2 years ago

Opened: https://github.com/nvim-lua/plenary.nvim/issues/331

shrkamat commented 2 years ago

Thanks @Shatur. This fixes the issue, but I don't see complete crash log in CMake build_and_run output.

In shell I see this extra info Floating point exception (core dumped) , so it's not super explicit about crash. (exit code 136 vs crashed exit 136).

exception

Shatur commented 2 years ago

In shell I see this extra info Floating point exception (core dumped)

Not sure why it not displayed... I catching all stdout and stderr.

shrkamat commented 2 years ago

Yes indeed both stderr and stdout is captures. Looks like is something to do with the shell (see last arg to subprocess.Popen).

#!/bin/python3

import subprocess

def print_lines(lines):
    if lines:
        print(lines.decode('utf-8'))
    else:
        print('None\n')

p = subprocess.Popen('./build/bin/nvim-cmake-plugin-test', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, start_new_session=False, shell=True)
stdout, stderror = p.communicate()
p.wait();

print('shell=True-------------------------------')
print_lines (stdout)
print_lines (stderror)
print ('shell=True exit code', p.returncode)
print('-----------------------------------------')

p = subprocess.Popen('./build/bin/nvim-cmake-plugin-test', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, start_new_session=False, shell=False)
stdout, stderror = p.communicate()
p.wait();

print('shell=False-------------------------------')
print_lines (stdout)
print_lines (stderror)
print ('exit code', p.returncode)
print('-----------------------------------------')

Output

shell=True-------------------------------
update : 0
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from NvimCMakePlugin
[ RUN      ] NvimCMakePlugin.ReportsNonZeroValueForFailedTest
/home/skamath/Projects/NVimCMakePluginTests/test.cpp:4: Failure
Value of: false
  Actual: false
Expected: true
[  FAILED  ] NvimCMakePlugin.ReportsNonZeroValueForFailedTest (0 ms)
[ RUN      ] NvimCMakePlugin.ReportsCrashedTestIncorrectly
Floating point exception (core dumped)

None

shell=True exit code 136
-----------------------------------------

shell=False-------------------------------
update : 0
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from NvimCMakePlugin
[ RUN      ] NvimCMakePlugin.ReportsNonZeroValueForFailedTest
/home/skamath/Projects/NVimCMakePluginTests/test.cpp:4: Failure
Value of: false
  Actual: false
Expected: true
[  FAILED  ] NvimCMakePlugin.ReportsNonZeroValueForFailedTest (0 ms)
[ RUN      ] NvimCMakePlugin.ReportsCrashedTestIncorrectly

None

exit code -8
-----------------------------------------

With shell=False even the exit code looks very different. Not sure what to infer from this.

Shatur commented 2 years ago

Can't help you here, Plenary don't have such option: https://github.com/nvim-lua/plenary.nvim/blob/9069d14a120cadb4f6825f76821533f2babcab92/lua/plenary/job.lua#L6

shrkamat commented 2 years ago

No issues, thanks for the plugin. It makes nvim much closer to IDE like experience. Appreciate it. Thanks.