Open parmi93 opened 10 months ago
@parmi93 I'll put some more thought into this, but the initial thought I have is that the current workaround that you have is likely a good one for the time being.
However, we could possibly add a setting that does this automatically, so I'll mark this as a request and we can track interest and priority by upvotes on the issue.
As for adding a new target in the UI, we do not currently support this and I believe it would be possibly difficult to manage injecting code into the makefile through a tool. The best way to add a target would be to modify your Makefile.
Thanks!
As for the second request, I explained myself poorly. What I meant to say was, how can I add options in the "MAKEFILE" panel?
Currently there is only Build target
, I would like to add a new option like Build test target
@parmi93 , hooking up a build command to Ctrl+S is a good workaround so far (except that indeed, on File->Save it wouldn't be triggered) and we can implement in future triggering it on any kind of save, via a new setting (eventually accompanied by a new UI element in the panel).
Now, about what targets to get built when the build action is executing. One entry-point is the "Build target: " UI element that in your screenshot is [Unset]. You click on the pencil, see all the makefile targets in a list and chose one (we have several work items for the future to make this a multi-selection, or add a new string that for any reason is not in the list...etc...). Now you would be able to chose this way your tests target, it would get built on Ctrl+S but this is not a good solution because that target only (not the rest, no "all"...) would be built when the extension is looking for information to parse for IntelliSense. Building that test target would produce the tests output and not compiler/linker commands which we need in order to calculate good IntelliSense in C/C++ files. So, whatever target you chose in the "Build target" UI element, will be built on Ctrl+S (due to your binding, otherwise not), on project load (when calculating IntelliSense), before any launch debug/run in terminal (in case you have the setting "makefie.buildBeforeLaunch") or when you invoke manually a build (clean or not) command.
As I understand your scenario, I suggest you add an entry to the array "makefile.configurations". Do you currently have anything defined within this setting? Look at settings.json. I am asking because in your screenshot I see "Configuration: [Unset]" (which is a default) and most probably you did not need this setting until now. But you can also have defined it without selecting one entry via the UI. If you already have configurations defined, just add to ".makeArgs" another string element with the name of the tests target but also the "all" (or a general build target so that we don't build only the tests target).
Or, in the makefile, can you define a dependency so that when "make" builds the tests target also builds a comprehensive complete enough (whatever your developer scenario needs) source code build target.
I think using the "makefile.configurations" setting is the cleanest way to achieve your scenario until we implement a more direct way of doing it.
Thanks for the reply, but now I'm even more confused. Is there any documentation I can consult to better understand how this tool works?
currently in my makefile I have the following targets:
all
: compile my production code, at the moment it only generates the object files, later it will also generate the "production executable"build_test
: compile/linking my tests source code by generating the executable all_tests.out
(this target depend on the all
target)run_test
: run the executable (all_tests.out
) generated by build_test
(this target depend on build_test
target)clean
: clean the build folderAs you suggested I associated the build_test
target to Build target
option
(I had previously associated it with the run_test
target, this way when I pressed Ctrl+S
it would compile and run my tests, now, as I expected, it just compiles.)
Now I have created the .vscode/settings.json
file:
{
"makefile.configurations": [
{
"name": "Default",
"makeArgs": []
}
],
"makefile.launchConfigurations": [
{
"cwd": "/home/parmi/Documents/SMARTConnect Core/test/build",
"binaryPath": "/home/parmi/Documents/SMARTConnect Core/test/build/all_tests.out"
}
]
}
I was hoping that by clicking on the play icon it would run the executable with the tests, but instead this is the error I get:
Cannot 'run' because there is no launch configuration set and the list of launch targets is empty. Double check the makefile configuration and the build target.
I guess I need to associate something with the Launch target
option, but I don't know how.
if I click on the pencil icon of Launch target
option, a text box appears with the words No launch targets identified
, while if I click on the pencil icon associated with the Configuration
option I can only select the Default
entry, but for some reason it seems that the tool does not accept this selection because Configuration
always remains [unset]
.
Hi @parmi93, sorry for the very long delay. I was going back through issues and checking for any responses I missed and saw this. Are you still facing this issue? I'd love to try and help you understand. Let me know, thanks!
I'm trying to use Test Driven Development for a new project, TDD requires you to run tests very often and one of the recommended techniques is to run the tests at every save instead of triggering the tests manually. I haven't been able to find a configuration anywhere that allows me to do this, as a workaround I have attached the
Build target
option to the Ctrl+s key combination, although it is not ideal because if I save viaFile->Save
the tests are not triggered.Also I was wondering how can I add a new target in the U.I.? in my case a target to run tests.