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

runtime(termdebug): Fix #12718 #14792

Closed
wants to merge 16 commits into from
Closed

runtime(termdebug): Fix #12718 #14792

wants to merge 16 commits into from

Conversation

ubaldot
Copy link
Contributor

@ubaldot ubaldot commented May 17, 2024

Hi!

This is my proposal for fixing #12718
I could have done something even more robust, like

if empty(glob('gdb'))
     file gdb
  elseif empty(glob(' Termdebug-gdb-console'))
     file Termdebug-gdb-console
  else
    Echoerr("You have a file/folder named 'gdb' or 'Termdebug-gdb-console'. Termdebug cannot start. Please rename them. ")
endif

Shall the same if-then-else condition be placed in other lines of the form file <hard-coded name> ?

OBS! I am not in the vim-dev mailing list!

@chrisbra
Copy link
Member

Thanks, are there other places where this could clash? I think the warning approach is good, although you have a leading white space inside your glob() function. Can you fix this up and add a test to https://github.com/vim/vim/blob/master/src/testdir/test_termdebug.vim ?

@ubaldot
Copy link
Contributor Author

ubaldot commented May 17, 2024

Sure thing! Yes, there are some other places where this could happen: pretty much everywhere where file command is used. You could /file in the source and see that you have it in other 2-3 places. I can use the same solution there as well. Regarding the tests: I never wrote a test for vimscripts, if there is some guideline it would be great to read! Finally: I will try to fix it during the weekend if I will find some time or during next week. Would that work?

@chrisbra
Copy link
Member

that sounds perfect. Regarding the tests, just check the existing termdebug test. It's not so hard, you basically need to create a gdb file and then check that either the plugin is not loaded (so you are still in a clean state, e.g. only one single buffer opened), or check if you can see the error message in the messages list. Or something like this :) Thanks for looking into this!

runtime/pack/dist/opt/termdebug/plugin/termdebug.vim Outdated Show resolved Hide resolved
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim Outdated Show resolved Hide resolved
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim Outdated Show resolved Hide resolved
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim Outdated Show resolved Hide resolved
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim Outdated Show resolved Hide resolved
src/testdir/test_termdebug.vim Outdated Show resolved Hide resolved
@k-takata k-takata changed the title Fix #12718 runtime(termdebug): Fix #12718 May 20, 2024
@ubaldot
Copy link
Contributor Author

ubaldot commented May 20, 2024

.. working on it. Please ignore all the pushes until I notify.

@ubaldot
Copy link
Contributor Author

ubaldot commented May 20, 2024

Check it now!
(yes, the previous bureplacement_filename was a typo!)

@ubaldot
Copy link
Contributor Author

ubaldot commented May 20, 2024

It seems some tests failed due to the following:

Failures: 
	From test_termdebug.vim:
	Found errors in Test_termdebug_bufnames():
	Caught exception in Test_termdebug_bufnames(): Vim(bwipeout):E517: No buffers were wiped out: bwipe! 12 @ command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[607]..function 
	

Most likely it is due to lines 319 and 332 of [src/testdir/test_termdebug.vim](https://github.com/vim/vim/pull/14792/files#diff-07567861d8244d8d0078cb5d13045a8fb5d438ec20af2d2341f648ca6d3b05f7) and it is not super clear to me how to solve it... any hints?

@k-takata
Copy link
Member

RunTheTest[57]..Test_termdebug_bufnames[20]..9_EndPromptDebug[9]..9_EndDebugCommon, line 4

The error occurs here:

src/testdir/test_termdebug.vim Outdated Show resolved Hide resolved
src/testdir/test_termdebug.vim Outdated Show resolved Hide resolved
src/testdir/test_termdebug.vim Outdated Show resolved Hide resolved
src/testdir/test_termdebug.vim Outdated Show resolved Hide resolved
@ubaldot
Copy link
Contributor Author

ubaldot commented May 21, 2024

Ready for review. :)

@k-takata
Copy link
Member

It seems that the following patch fixes the CI failure:

--- a/src/testdir/test_termdebug.vim
+++ b/src/testdir/test_termdebug.vim
@@ -317,10 +317,9 @@ func Test_termdebug_bufnames()
   call WaitForAssert({-> assert_false(bufexists(filename))})
   call WaitForAssert({-> assert_true(bufexists(replacement_filename))})
   quit!
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
 
   " Check if error message is in :message
-  " Delay for securing that Termdebug is shutoff
-  sleep 1
   let g:termdebug_config['disasm_window'] = 1
   let filename = 'Termdebug-asm-listing'
   call writefile(['This', 'is', 'a', 'test'], filename, 'D')
@@ -328,10 +327,11 @@ func Test_termdebug_bufnames()
   let error_message = "You have a file/folder named '" .. filename .. "'"
   Termdebug
   sleep 2
-  call WaitForAssert({->assert_notequal(-1, stridx(execute('messages'), error_message))})
+  call WaitForAssert({-> assert_notequal(-1, stridx(execute('messages'), error_message))})
   quit!
-  wincmd t
+  wincmd b
   wincmd q
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
 
   unlet g:termdebug_config
 endfunc

@ubaldot
Copy link
Contributor Author

ubaldot commented May 21, 2024

Changes implemented.

@ubaldot
Copy link
Contributor Author

ubaldot commented May 21, 2024

Hum... still does not pass some CI tests.

I am wondering if the following shall be changed somewhere as well...

--- a/src/testdir/test_termdebug.vim
+++ b/src/testdir/test_termdebug.vim

@k-takata
Copy link
Member

Hmm, it passed in my repository...
https://github.com/k-takata/vim/actions/runs/9173423210
Commit: k-takata@f9523a2

@ubaldot
Copy link
Contributor Author

ubaldot commented May 21, 2024

Hum... could you double check my changes to check if I did everything right?

Co-authored-by: K.Takata <kentkt@csc.jp>
@ubaldot
Copy link
Contributor Author

ubaldot commented May 21, 2024

Usch! Hopefully one day someone will make a Vim/Vim9 language server to catch these typos :D

call writefile(['This', 'is', 'a', 'test'], filename, 'D')
" Throw away the file once the test has done.
Termdebug
sleep 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hard-coded sleeps in tests will increase the time it takes to run the tests. Can you change these
to WaitForAssert() calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I replaced the sleep 2 with call WaitForAssert({-> assert_equal(3, winnr('$'))} , which, in my understanding, wait until the third window is available (in this case, given the termdebug setup, it means that termdebug is up and running).

" Check only the head of the error message
let error_message = "You have a file/folder named '" .. filename .. "'"
Termdebug
sleep 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace this hard-coded sleep with WaitForAssert()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Sorry for so many commits, it's my first time. I wish I could test the CI on my fork first... shall I cancel the PR if the CI still fails?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. After all, that's what we have CI for ;) BTW: you can also run the tests locally: https://github.com/vim/vim/blob/master/src/testdir/README.txt

Just need to run make test_termdebug.res and then check the test.log and messages file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWESOME! I am going to give it a shot straight away. :)

Copy link
Contributor Author

@ubaldot ubaldot May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the README

RUNNING THE TESTS:

To run a single test from the src directory:

    $ make test_<name>

The below commands should be run from the src/testdir directory.

To run a single test:

    $ make test_<name>.res

I am in ./vim/src/testdir but when I run make test_termdebug.res I get make: *** No rule to make target '../vim', needed by 'test_termdebug.res'. Stop. Perhaps there is some requirement that I am missing?

EDIT:
make VIMPROG=/usr/bin/vim test_termdebug.res seems working...

Copy link
Member

@chrisbra chrisbra May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go up and directory and make vim first (cd .. && make)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I built the vim executable. The test run but it seems that my tests are not run:

$ make test_termdebug.res
VIMRUNTIME=../../runtime  ../vim -f  -u unix.vim --gui-dialog-file guidialog -U NONE --noplugin --not-a-term -S runtest.vim test_termdebug.vim --cmd 'au SwapExists * let v:swapchoice = "e"' | LC_ALL=C LANG=C LANGUAGE=C awk '/Executing Test_/{match($0, "([0-9][0-9]:[0-9][0-9] *)?Executing Test_[^\\)]*\\)"); print substr($0, RSTART, RLENGTH) "\r"; fflush()}'
02:05 Executing Test_termdebug_basic()
02:09 Executing Test_termdebug_bufnames()
02:09 Executing Test_termdebug_mapping()
02:09 Executing Test_termdebug_tbreak() 

It is missing Test_termdebug_bufnames(). Shall I add it to some other file?

@chrisbra
Copy link
Member

thanks, looks good now.

@chrisbra chrisbra closed this in 62ccaa6 May 21, 2024
clason added a commit to clason/neovim that referenced this pull request May 21, 2024
runtime(termdebug): check for gdb file/dir before using as buffer name

Add test so that this doesn't regress.

fixes: vim/vim#12718
closes: vim/vim#14792

vim/vim@62ccaa6

Co-authored-by: Ubaldo Tiberi <ubaldo.tiberi@volvo.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request May 22, 2024
…using as buffer name

Add test so that this doesn't regress.

fixes: vim/vim#12718
closes: vim/vim#14792

vim/vim@62ccaa6

Co-authored-by: Ubaldo Tiberi <ubaldo.tiberi@volvo.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request May 22, 2024
…using as buffer name (#28908)

Add test so that this doesn't regress.

fixes: vim/vim#12718
closes: vim/vim#14792

vim/vim@62ccaa6

Co-authored-by: Ubaldo Tiberi <ubaldo.tiberi@volvo.com>
huangyingw pushed a commit to huangyingw/neovim that referenced this pull request May 31, 2024
…using as buffer name (neovim#28908)

Add test so that this doesn't regress.

fixes: vim/vim#12718
closes: vim/vim#14792

vim/vim@62ccaa6

Co-authored-by: Ubaldo Tiberi <ubaldo.tiberi@volvo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants