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

Is it possible to call cmake build before run? #127

Closed
xgdgsc opened this issue Sep 6, 2019 · 7 comments
Closed

Is it possible to call cmake build before run? #127

xgdgsc opened this issue Sep 6, 2019 · 7 comments
Labels
good first issue Good for newcomers

Comments

@xgdgsc
Copy link

xgdgsc commented Sep 6, 2019

Is your feature request related to a problem? Please describe.
Currently when I change code and want to test and click run. It runs the old binary.

Describe the solution you'd like
Call cmake build first before run.

@matepek
Copy link
Owner

matepek commented Sep 7, 2019

It works the other way around. You build your binary and the extension detects it and re-run it.
Check this conversation for further details.
enable autorun

For building from vscode: check this.

Here is my tasks.json for example:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "clean rebuild (debug)",
            "type": "shell",
            "group": "none",
            "command": " rm -rf debug; mkdir debug; cd debug; cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../.. && ninja",
            "options": {
                "cwd": "${workspaceFolder}/out"
            },
            "windows": {
                "command": "cmd.exe",
                "args": [
                    "/C",
                    "cd . && cd debug && del /S /Q /F * >NUL && vcvarsall.bat amd64 && cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ../.. && cd ."
                ]
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            },
            "problemMatcher": []
        },
        {
            "label": "ninja (debug)",
            "type": "process",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "ninja",
            "options": {
                "cwd": "${workspaceFolder}/out/debug"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}/out/debug"
                ]
            },
        }
    ]
}

@matepek matepek changed the title Possible to call cmake build before run Is it possible to call cmake build before run? Sep 7, 2019
@matepek matepek pinned this issue Sep 7, 2019
@matepek matepek added the good first issue Good for newcomers label Sep 7, 2019
@matepek matepek closed this as completed Sep 7, 2019
@xgdgsc
Copy link
Author

xgdgsc commented Sep 8, 2019

OK. Thanks.

@matepek
Copy link
Owner

matepek commented Jul 27, 2020

@yudi-azvd
Copy link

yudi-azvd commented Feb 21, 2021

@xgdgsc I found a way to run tests automatically. Install the extension Trigger Task on Save and configure it to trigger a task with the label, let's say, "Build tests" when files are saved. You can choose which files with patterns (src/*.cpp, tests/*.cpp).

Then create a task in .vscode/tasks.json labeled "Build tests" which will build your tests by calling make, g++ or something else you use in your project. I'm using something like this and it's working fine for now:

{
      "label": "Build tests",
      "type": "shell",
      "presentation": {
        "echo": false,
        "reveal": "always",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": false,
        "clear": true
      },
      "command": "make tests", //shell/terminal command to build tests
      "problemMatcher": []
    }

And make sure to have autorun from the Test Explorer enabled like matepek mentioned.

Hope it is useful.

@George-Gi
Copy link

I am looking for a way to first build the tests, if a source file has changed, and then run the tests. Ideally this sequence taking place by hitting the "Run Tests" icon. In the TestMate version 4.3.5 I don't see the option "Enable Autorun". Any suggestions?

@appden
Copy link
Contributor

appden commented Nov 29, 2022

Just in case this helps, I have it setup to build my tests with cmake before running tests in the UI.

My settings.json includes this:

    "testMate.cpp.test.advancedExecutables": [
        {
            ...
            "runTask": {
                "before": [
                    "build tests",
                ],
            },
        },
    ],

And tasks.json leverages CMake Tools extension to run the build:

        {
            "label": "build tests",
            "type": "cmake",
            "command": "build",
            "group": "build",
            "targets": [
                "test/all"
            ]
        },

@jnz86
Copy link

jnz86 commented Dec 4, 2023

Just in case this helps, I have it setup to build my tests with cmake before running tests in the UI.

So, I like this and tried it, but ran into an issue.

If you mess up your build, you might miss something important. For me what would happen is my test would attempt to build, fail, the old exec would still be there and the test would run it. Likewise, you can't clean the old execs, because the test explorer won't see them anymore.

For me, it would attempt to build automatically when I clicked test, fail build, then report a success or fail (whatever my last correctly built test was). If I didn't look to see in my output that it failed, it could be easy to miss.

Mate responded to my question about this that it wasn't intended to run like that and it was probably better to run the tests when the exec changes. This way, a failed build won't run a test at all.

For me, this changes my flow to build tests in order to run them, instead of clicking test to build then run. It's a small difference but important.

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

No branches or pull requests

6 participants