www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How debugg unittest with visual code + code-d

reply Luis <luis.panadero gmail.com> writes:
So I actually managed to "debug" my unittests but It requires 
that I run previsuly "dub test" on console, so the executable is 
update. As I understand, I need to setup a task to be prelaunched 
by debug to generate the unittest executable, but I don't know 
how setup it correctly. I only manage to build the library, but 
not the unittest executable.

Also, how hell I can see the content of a array on the debugger? 
I only see the length and "pointer" property. I try to add a 
watch expression to these pointer with the " " but the show 
content, don't matches the real stuff on the array... This it's 
forcing me to use the old classic "debug with printfs" with it's 
annoying if you have pure  nogc nothrow annotated code.


I have the impression that debugging D has get worse in this last 
years. I remember debuging with "ddd" with zero issues like five 
years ago, and now I keep hitting all kind of troubles with 
anything that I try.
Jun 05 2020
parent reply WebFreak001 <d.forum webfreak.org> writes:
On Friday, 5 June 2020 at 17:03:40 UTC, Luis wrote:
 So I actually managed to "debug" my unittests but It requires 
 that I run previsuly "dub test" on console, so the executable 
 is update. As I understand, I need to setup a task to be 
 prelaunched by debug to generate the unittest executable, but I 
 don't know how setup it correctly. I only manage to build the 
 library, but not the unittest executable.

 Also, how hell I can see the content of a array on the 
 debugger? I only see the length and "pointer" property. I try 
 to add a watch expression to these pointer with the " " but the 
 show content, don't matches the real stuff on the array... This 
 it's forcing me to use the old classic "debug with printfs" 
 with it's annoying if you have pure  nogc nothrow annotated 
 code.


 I have the impression that debugging D has get worse in this 
 last years. I remember debuging with "ddd" with zero issues 
 like five years ago, and now I keep hitting all kind of 
 troubles with anything that I try.
To build before running the debugger, add the following task to your task definitions file (Ctrl-Shift-B): { "label": "dub build", // <-- add a good name here "type": "dub", "run": false, "buildType": "unittest", // <-- this makes it build the unittests "problemMatcher": [ "$dmd" ], "group": "build" } And in the debug configuration add the preLaunchTask with the given label: { "version": "0.2.0", "configurations": [ { ..., "preLaunchTask": "dub build" } ] } For more information consult the User Guide (F1 -> code-d User Guide / Documentation) and see the Debugging section. Directly debugging the unittests from code-d is not supported yet, but is in planning. About the debugging printing: pretty printers might make it look worse than it would be with the plain GDB formatter. But definitely this could be improved. If you use the Native Debug extension it should default to the plain value printer, which in turn might make other stuff not look so good. If you use the C/C++ extension, you might be able to have better support if you add a Natvis file. Void-995 wrote a D natvis file like 2 years ago, which was never fully finished (DL: https://www.dropbox.com/s/t5yejma3w7cbna9/dlang.natvis?dl=1 ; mirror: https://wfr.moe/f6xBDC/dlang.natvis), so I'm not sure how well that works now. Btw if you use the latest serve-d version (release channel "nightly") you will have snippets to insert debug printf statements like debug { import std.stdio : writeln; try { writeln(""); } catch (Exception) {} } debug { import std.stdio : writefln; try { writefln!""(); } catch (Exception) {} } debug { import core.stdc.stdio : printf; printf("\n"); } which work in nogc safe nothrow pure
Jun 05 2020
parent reply Luis <luis.panadero gmail.com> writes:
On Friday, 5 June 2020 at 18:13:52 UTC, WebFreak001 wrote:
 To build before running the debugger, add the following task to 
 your task definitions file (Ctrl-Shift-B):

 {
 	"label": "dub build", // <-- add a good name here
 	"type": "dub",
 	"run": false,
 	"buildType": "unittest", // <-- this makes it build the 
 unittests
 	"problemMatcher": [
 		"$dmd"
 	],
 	"group": "build"
 }
It isn't working correctly on my case : I get this error : Performing "unittest" build using dmd for x86_64. ddiv ~sparseSet: building configuration "unittest"... ../../../.dub/packages/silly-1.0.2/silly/silly.d(15,2): Error: static assert: "Couldn't find 'dub_test_root'. Make sure you are running tests with dub test" dmd failed with exit code 1. The terminal process terminated with exit code: 2 And this works fine if I run a dub test from console.
Jun 06 2020
next sibling parent Andre Pany <andre s-e-a-p.de> writes:
On Saturday, 6 June 2020 at 08:06:02 UTC, Luis wrote:
 On Friday, 5 June 2020 at 18:13:52 UTC, WebFreak001 wrote:
 To build before running the debugger, add the following task 
 to your task definitions file (Ctrl-Shift-B):

 {
 	"label": "dub build", // <-- add a good name here
 	"type": "dub",
 	"run": false,
 	"buildType": "unittest", // <-- this makes it build the 
 unittests
 	"problemMatcher": [
 		"$dmd"
 	],
 	"group": "build"
 }
It isn't working correctly on my case : I get this error : Performing "unittest" build using dmd for x86_64. ddiv ~sparseSet: building configuration "unittest"... ../../../.dub/packages/silly-1.0.2/silly/silly.d(15,2): Error: static assert: "Couldn't find 'dub_test_root'. Make sure you are running tests with dub test" dmd failed with exit code 1. The terminal process terminated with exit code: 2 And this works fine if I run a dub test from console.
In my case, I just execute dub test from VSC terminal, use the auto generated debugger configuration and just set the unittest executable path. This works fine on linux (WSL). Kind regards Andre
Jun 06 2020
prev sibling parent reply WebFreak001 <d.forum webfreak.org> writes:
On Saturday, 6 June 2020 at 08:06:02 UTC, Luis wrote:
 On Friday, 5 June 2020 at 18:13:52 UTC, WebFreak001 wrote:
 [...]
It isn't working correctly on my case : I get this error : Performing "unittest" build using dmd for x86_64. ddiv ~sparseSet: building configuration "unittest"... ../../../.dub/packages/silly-1.0.2/silly/silly.d(15,2): Error: static assert: "Couldn't find 'dub_test_root'. Make sure you are running tests with dub test" dmd failed with exit code 1. The terminal process terminated with exit code: 2 And this works fine if I run a dub test from console.
You can change it to { "label": "dub build", // <-- add a good name here "type": "dub", "test": true, "problemMatcher": [ "$dmd" ], "group": "build" } but it will run the unittests then too (not just build them), which will increase the task running time
Jun 06 2020
parent Luis <luis.panadero gmail.com> writes:
On Saturday, 6 June 2020 at 08:42:22 UTC, WebFreak001 wrote:
 On Saturday, 6 June 2020 at 08:06:02 UTC, Luis wrote:
 On Friday, 5 June 2020 at 18:13:52 UTC, WebFreak001 wrote:
 [...]
It isn't working correctly on my case : I get this error : Performing "unittest" build using dmd for x86_64. ddiv ~sparseSet: building configuration "unittest"... ../../../.dub/packages/silly-1.0.2/silly/silly.d(15,2): Error: static assert: "Couldn't find 'dub_test_root'. Make sure you are running tests with dub test" dmd failed with exit code 1. The terminal process terminated with exit code: 2 And this works fine if I run a dub test from console.
You can change it to { "label": "dub build", // <-- add a good name here "type": "dub", "test": true, "problemMatcher": [ "$dmd" ], "group": "build" } but it will run the unittests then too (not just build them), which will increase the task running time
It works! Now, I would try these "natvis"
Jun 06 2020