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

Display correct filename with --test option #39597

Merged
merged 2 commits into from
Feb 8, 2017

Conversation

GuillaumeGomez
Copy link
Member

Fixes #39592.

With the current files:

test.rs

pub mod foo;

/// This is a Foo;
///
/// ```
/// println!("baaaaaar");
/// ```
#[unstable]
pub struct Foo;

/// This is a Bar;
///
/// ```
/// println!("fooooo");
/// ```
pub struct Bar;

foo.rs

// note the whitespaces
/// ```
/// println!("foo");
/// ```
pub fn foo() {}

It displays:

./build/x86_64-apple-darwin/stage1/bin/rustdoc --test test.rs

running 3 tests
test test.rs - line 13 ... ok
test test.rs - line 5 ... ok
test foo.rs - line 2 ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured

And with a markdown file:

# foo

` ``
println!("lol");
` ``

asdjnfasd

asd

It displays:

./build/x86_64-apple-darwin/stage1/bin/rustdoc --test foo.md

running 1 test
test <input> - line 3 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

r? @alexcrichton

@alexcrichton
Copy link
Member

Can you be sure to add a test for this as well?

@GuillaumeGomez
Copy link
Member Author

@alexcrichton: So I came up with a solution, does it seem ok to you?

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 7, 2017

📌 Commit d92abb3 has been approved by alexcrichton

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
…_file, r=alexcrichton

Display correct filename with --test option

Fixes rust-lang#39592.

With the current files:

```rust
pub mod foo;

/// This is a Foo;
///
/// ```
/// println!("baaaaaar");
/// ```
pub struct Foo;

/// This is a Bar;
///
/// ```
/// println!("fooooo");
/// ```
pub struct Bar;
```

```rust
// note the whitespaces
/// ```
/// println!("foo");
/// ```
pub fn foo() {}
```

It displays:

```
./build/x86_64-apple-darwin/stage1/bin/rustdoc --test test.rs

running 3 tests
test test.rs - line 13 ... ok
test test.rs - line 5 ... ok
test foo.rs - line 2 ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured
```

```

` ``
println!("lol");
` ``

asdjnfasd

asd
```

It displays:

```
./build/x86_64-apple-darwin/stage1/bin/rustdoc --test foo.md

running 1 test
test <input> - line 3 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
```

r? @alexcrichton
&format!("Not found doc test: \"{}\" in {:?}", s, v),
&res);
let path = tmp[0].rsplit("test ").next().unwrap();
println!("{:?}", path);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this println really supposed to be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, absolutely not! Thanks a lot for notifying it!

@SergioBenitez
Copy link
Contributor

SergioBenitez commented Feb 8, 2017

I don't know if this PR addresses the entire issue. Another thing that I can't do anymore is run a subset of the doctests by specifying a prefix: cargo test some_module. Doing this currently runs the unit tests, but not doctests, for that prefix. This is another fairly large, breaking regression. Is this fixed by this PR?

This PR also doesn't address another part of #39592: the module/function name being tested is no longer printed. I have no idea what's on line 194 of user.rs, but I do know what the function get_current_user is supposed to do.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Feb 8, 2017

@bors: r+ r=alexcrichton

@bors
Copy link
Contributor

bors commented Feb 8, 2017

📌 Commit d2f8abf has been approved by alexcrichton

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Feb 8, 2017

@SergioBenitez: cargo test is based on name so if you want to run "specific" doc tests, you should specify the filename instead. Also, the ids of rustdoc were pretty stupid, now at least you know from which file and which line it comes from (and then you can go read the corresponding code directly).

@SergioBenitez
Copy link
Contributor

This is not the way things worked before, however, and frankly, I don't believe this makes any sense. There is now a strange inconsistency between cargo test {name} when running doctests vs. unit tests, an inconsistency that didn't exist before. I can't run all of the tests for a single module with a single command anymore. Now, I have to figure out the path to a module, run the module's unit tests, and then run the modules doctests. This is a major usability regression.

I think this is incredibly confusing. What does "the ids of rustdoc were pretty stupid" mean? It's great that I now know the file/line the test is on (by the way, are those numbers actually correct? I'm seeing some strange numbers...), but I also want to know the logical path to the module. Like I said, I have no idea which function/item is in which file/line, and forcing me to check out the file individually is a huge bummer. I want to know the file/line if I'm going to go and fix it, but I want to know the module path when I just want to know what went wrong. Both pieces of information are useful. Nothing is stupid about wanting to have the full picture.

@GuillaumeGomez
Copy link
Member Author

The ids were stupid because they generally didn't give much indication. What happens if you have the same function name in multiple traits? Simply something beautiful like this:

func_0
func_1
func_2
func_3
func_4
...

Super useful, indeed. And I don't even speak when you run rustdoc --test on markdown files. No, clearly, this new system is way better. With the fix, all the files will be correctly printed.

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
…_file, r=alexcrichton

Display correct filename with --test option

Fixes rust-lang#39592.

With the current files:

```rust
pub mod foo;

/// This is a Foo;
///
/// ```
/// println!("baaaaaar");
/// ```
pub struct Foo;

/// This is a Bar;
///
/// ```
/// println!("fooooo");
/// ```
pub struct Bar;
```

```rust
// note the whitespaces
/// ```
/// println!("foo");
/// ```
pub fn foo() {}
```

It displays:

```
./build/x86_64-apple-darwin/stage1/bin/rustdoc --test test.rs

running 3 tests
test test.rs - line 13 ... ok
test test.rs - line 5 ... ok
test foo.rs - line 2 ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured
```

```

` ``
println!("lol");
` ``

asdjnfasd

asd
```

It displays:

```
./build/x86_64-apple-darwin/stage1/bin/rustdoc --test foo.md

running 1 test
test <input> - line 3 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
```

r? @alexcrichton
bors added a commit that referenced this pull request Feb 8, 2017
Rollup of 11 pull requests

- Successful merges: #39462, #39512, #39529, #39557, #39561, #39582, #39583, #39597, #39622, #39624, #39630
- Failed merges:
@bors bors merged commit d2f8abf into rust-lang:master Feb 8, 2017
@alexcrichton
Copy link
Member

@GuillaumeGomez it seems like both indicators could be inserted in the test name, right? We could have both a small snippet of what file and also the old historical context for what's actually being tested.

@GuillaumeGomez GuillaumeGomez deleted the correct_rustdoc_test_file branch February 8, 2017 21:05
@SergioBenitez
Copy link
Contributor

The ids were stupid because they generally didn't give much indication. What happens if you have the same function name in multiple traits? Simply something beautiful like this:

func_0
func_1
func_2
func_3
func_4
...

Super useful, indeed.

That's not what Cargo prints out at all. This is what gets printed out:

running 6 tests
test MyTrait::a_0 ... ok
test A::a_0 ... ok
test B::a_0 ... ok
test A::a_0 ... ok
test MyOtherTrait::a_0 ... ok
test B::a_0 ... ok

The logs includes the full path to the trait/function, not just the function name, thus disambiguating. I do agree that the _n is a bit odd, but you get used to it very quickly. I'd personally like to see #n instead: MyTrait::a#0, MyTrait::a#1, and so on. Or maybe even, MyTrait::a test 1, MyTrait::a test 2, and so on. Or not use it at all an disambiguate with the file/line, as I'll show below.

The other issue I have with this new format is that it uses absolute paths; they're just too long. I don't care about the absolute path to my project; I ran cargo test, I'm in the workspace. I think the path should be relative to the current Cargo workspace or Cargo root.

I think something like this would look nice:

test MyTrait::a (src/lib.rs:2) ... ok
test A::a (src/lib.rs:9) ... ok
test B::a (src/lib.rs:33) ... ok
test A::a (src/lib.rs:19) ... ok
test MyOtherTrait::a (src/lib.rs:40) ... ok
test B::a (src/lib.rs:26) ... ok

This is concise, informative, and includes all of the old and new information.

@GuillaumeGomez
Copy link
Member Author

Having the two pieces of information could be useful, indeed. I can add it back (without the _n if you don't mind). Could you open an issue for it please?

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.

4 participants