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

extra: Capture stdout/stderr of tests by default #12215

Closed

Conversation

alexcrichton
Copy link
Member

When tests fail, their stdout and stderr is printed as part of the summary, but
this helps suppress failure messages from #[should_fail] tests and generally
clean up the output of the test runner.

@alexcrichton
Copy link
Member Author

With this test:

#[test]
fn test1() {
    fail!()
}
#[test]
fn test2() {
}
#[test]
#[should_fail]
fn test3() {
    fail!()
}
#[test]
#[should_fail]
fn test4() {
}

BEFORE


running 4 tests
task 'test1' failed at 'explicit failure', foo.rs:3
task 'test3' failed at 'explicit failure', foo.rs:11
test test2 ... ok
test test4 ... FAILED
test test1 ... FAILED
test test3 ... ok

failures:
    test1
    test4

test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured

task '<main>' failed at 'Some tests failed', /Users/alex/code/rust3/src/libextra/test.rs:167

AFTER


running 4 tests
test test2 ... ok
test test1 ... FAILED
test test3 ... ok
test test4 ... FAILED

failures:

---- test1 stdout ----
        task 'test1' failed at 'explicit failure', foo.rs:3


failures:
    test1
    test4

test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured

task '<main>' failed at 'Some tests failed', /Users/alex/code/rust-opt/src/libextra/test.rs:166

if stdout.len() > 0 {
fail_out.push_str(format!("---- {} stdout ----\n\t",
f.name.to_str()));
let output = str::from_utf8(*stdout).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

from_utf8_lossy seems like it'd make more sense here.

@alexcrichton
Copy link
Member Author

Updated with from_utf8_lossy

@adrientetar
Copy link
Contributor

👌

When tests fail, their stdout and stderr is printed as part of the summary, but
this helps suppress failure messages from #[should_fail] tests and generally
clean up the output of the test runner.
@alexcrichton alexcrichton deleted the test-stdout-capture branch February 14, 2014 21:58
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
…ion-in-vscode-settings, r=Veykril

feat: Support variable substitution in VSCode settings

Currently support a subset of [variables provided by VSCode](https://code.visualstudio.com/docs/editor/variables-reference) in `server.extraEnv` section of Rust-Analyzer settings:

  * `workspaceFolder`
  * `workspaceFolderBasename`
  * `cwd`
  * `execPath`
  * `pathSeparator`

Also, this PR adds support for general environment variables resolution. You can declare environment variables and reference them from other variables like this:

```JSON
"rust-analyzer.server.extraEnv": {
    "RUSTFLAGS": "-L${env:OPEN_XR_SDK_PATH}",
    "OPEN_XR_SDK_PATH": "${workspaceFolder}\\..\\OpenXR-SDK\\build\\src\\loader\\Release"
},
```
The order of variable declaration doesn't matter, you can reference variables before defining them. If the variable is not present in `extraEnv` section, VSCode will search for them in your environment. Missing variables will be replaced with empty string. Circular references won't be resolved and will be passed to rust-analyzer server process as is.

Closes rust-lang#9626, but doesn't address use cases where people want to use values provided by `rustc` or `cargo`, such as `${targetTriple}` proposal rust-lang#11649
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.

3 participants