Skip to content

Conversation

@vsrs
Copy link
Contributor

@vsrs vsrs commented Jul 3, 2020

This PR adds on option to specify (in the settings.json) environment variables passed to the runnable.
The simplest way for all runnables in a bunch:

    "rust-analyzer.runnableEnv": {
        "RUN_SLOW_TESTS": "1"
    }

Or it is possible to specify vars more granularly:

    "rust-analyzer.runnableEnv": [
        {
            // "mask": null, // null mask means that this rule will be applied for all runnables
            env: {
                 "APP_ID": "1",
                 "APP_DATA": "asdf"
            }
        },
        {
            "mask": "test_name",
            "env": {
                 "APP_ID": "2", // overwrites only APP_ID
            }
        }
    ]

You can use any valid RegExp as a mask. Also note that a full runnable name is something like run bin_or_example_name, test some::mod::test_name or test-mod some::mod, so it is possible to distinguish binaries, single tests, and test modules with this masks: "^run", "^test " (the trailing space matters!), and "^test-mod" respectively.

Fixes #4450

I suppose this info should be somewhere in the docs, but unsure where is the best place.

@matklad
Copy link
Contributor

matklad commented Jul 3, 2020

I suppose this info should be somewhere in the docs, but unsure where is the best place.

I think we need top-level section in manual.adoc for this:

== Editor Features
==== VS Code

@vsrs
Copy link
Contributor Author

vsrs commented Jul 3, 2020

@matklad I added the doc section.

@matklad
Copy link
Contributor

matklad commented Jul 3, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 3, 2020

@bors bors bot merged commit 8489145 into rust-lang:master Jul 3, 2020
@vsrs vsrs deleted the runnable_env branch July 3, 2020 14:11
@adaszko
Copy link
Contributor

adaszko commented Feb 2, 2021

Are those environment variables also applied when clicking the "Debug" code lens over a unit test in VSCode?

@vsrs
Copy link
Contributor Author

vsrs commented Feb 2, 2021

Yes, they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment variables when running tests

3 participants