- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          [rustdoc] Correctly handle should_panic doctest attribute and fix --no-run test flag on the 2024 edition
          #143900
        
          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
          
     Closed
      
      
    
  
     Closed
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      07d41a7
              
                Correctly handle `--no-run` rustdoc test option
              
              
                GuillaumeGomez 796c4ef
              
                Correctly handle `should_panic` doctest attribute
              
              
                GuillaumeGomez 11b7070
              
                Add regression test for #143009
              
              
                GuillaumeGomez 21a4d9d
              
                Update std doctests
              
              
                GuillaumeGomez 5f2ae4f
              
                Add regression test for #143858
              
              
                GuillaumeGomez b001ba6
              
                Add FIXME comments to use `test::ERROR_EXIT_CODE` once public and fix…
              
              
                GuillaumeGomez 030b664
              
                Use libtest `ERROR_EXIT_CODE` constant
              
              
                GuillaumeGomez 560d450
              
                Correctly handle `should_panic` on targets not supporting it
              
              
                GuillaumeGomez b70e20a
              
                Correctly handle `-C panic=abort` in doctests
              
              
                GuillaumeGomez 6060bcc
              
                Improve error messages for failing `should_panic` doctests
              
              
                GuillaumeGomez File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Ensure that `should_panic` doctests only succeed if the test actually panicked. | ||
| // Regression test for <https://github.com/rust-lang/rust/issues/143009>. | ||
|  | ||
| //@ ignore-cross-compile | ||
|  | ||
| use run_make_support::rustdoc; | ||
|  | ||
| fn check_output(edition: &str, panic_abort: bool) { | ||
| let mut rustdoc_cmd = rustdoc(); | ||
| rustdoc_cmd.input("test.rs").arg("--test").edition(edition); | ||
| if panic_abort { | ||
| rustdoc_cmd.args(["-C", "panic=abort"]); | ||
| } | ||
| let output = rustdoc_cmd.run_fail().stdout_utf8(); | ||
| let should_contain = &[ | ||
| "test test.rs - bad_exit_code (line 1) ... FAILED", | ||
| "test test.rs - did_not_panic (line 6) ... FAILED", | ||
| "test test.rs - did_panic (line 11) ... ok", | ||
| "---- test.rs - bad_exit_code (line 1) stdout ---- | ||
| Test executable failed (exit status: 1).", | ||
| "---- test.rs - did_not_panic (line 6) stdout ---- | ||
| Test didn't panic, but it's marked `should_panic`.", | ||
| "test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;", | ||
| ]; | ||
| for text in should_contain { | ||
| assert!( | ||
| output.contains(text), | ||
| "output (edition: {edition}) doesn't contain {:?}\nfull output: {output}", | ||
| text | ||
| ); | ||
| } | ||
| } | ||
|  | ||
| fn main() { | ||
| check_output("2015", false); | ||
|  | ||
| // Same check with the merged doctest feature (enabled with the 2024 edition). | ||
| check_output("2024", false); | ||
|  | ||
| // Checking that `-C panic=abort` is working too. | ||
| check_output("2015", true); | ||
| check_output("2024", true); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /// ``` | ||
| /// std::process::exit(1); | ||
| /// ``` | ||
| fn bad_exit_code() {} | ||
|  | ||
| /// ```should_panic | ||
| /// std::process::exit(1); | ||
| /// ``` | ||
| fn did_not_panic() {} | ||
|  | ||
| /// ```should_panic | ||
| /// panic!("yeay"); | ||
| /// ``` | ||
| fn did_panic() {} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|  | ||
| running 7 tests | ||
| test $DIR/no-run.rs - f (line 14) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 17) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 20) ... ignored | ||
| test $DIR/no-run.rs - f (line 23) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 29) - compile fail ... ok | ||
| test $DIR/no-run.rs - f (line 34) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 38) - compile ... ok | ||
|  | ||
| test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|  | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
|  | ||
| running 5 tests | ||
| test $DIR/no-run.rs - f (line 14) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 17) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 23) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 34) - compile ... ok | ||
| test $DIR/no-run.rs - f (line 38) - compile ... ok | ||
|  | ||
| test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|  | ||
|  | ||
| running 2 tests | ||
| test $DIR/no-run.rs - f (line 20) ... ignored | ||
| test $DIR/no-run.rs - f (line 29) - compile fail ... ok | ||
|  | ||
| test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|  | ||
| all doctests ran in $TIME; merged doctests compilation took $TIME | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.