- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Compiletest: Custom differ #131181
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
          
     Merged
      
      
    
  
     Merged
                    Compiletest: Custom differ #131181
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
|  | @@ -2459,7 +2459,7 @@ impl<'test> TestCx<'test> { | |
| } | ||
| } | ||
|  | ||
| fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize { | ||
| fn compare_output(&self, stream: &str, actual: &str, expected: &str) -> usize { | ||
| let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) { | ||
| // FIXME: We ignore the first line of SVG files | ||
| // because the width parameter is non-deterministic. | ||
|  | @@ -2499,56 +2499,66 @@ impl<'test> TestCx<'test> { | |
| (expected, actual) | ||
| }; | ||
|  | ||
| // Write the actual output to a file in build/ | ||
| let test_name = self.config.compare_mode.as_ref().map_or("", |m| m.to_str()); | ||
| let actual_path = self | ||
| .output_base_name() | ||
| .with_extra_extension(self.revision.unwrap_or("")) | ||
| .with_extra_extension(test_name) | ||
| .with_extra_extension(stream); | ||
|  | ||
| if let Err(err) = fs::write(&actual_path, &actual) { | ||
| self.fatal(&format!("failed to write {stream} to `{actual_path:?}`: {err}",)); | ||
| } | ||
| println!("Saved the actual {stream} to {actual_path:?}"); | ||
|  | ||
| let expected_path = | ||
| expected_output_path(self.testpaths, self.revision, &self.config.compare_mode, stream); | ||
|  | ||
| if !self.config.bless { | ||
| if expected.is_empty() { | ||
| println!("normalized {}:\n{}\n", kind, actual); | ||
| println!("normalized {}:\n{}\n", stream, actual); | ||
| } else { | ||
| println!("diff of {}:\n", kind); | ||
| print!("{}", write_diff(expected, actual, 3)); | ||
| println!("diff of {stream}:\n"); | ||
| if let Some(diff_command) = self.config.diff_command.as_deref() { | ||
| let mut args = diff_command.split_whitespace(); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark: technically this is very wonky and not robust, i.e.  | ||
| let name = args.next().unwrap(); | ||
| match Command::new(name) | ||
| .args(args) | ||
| .args([&expected_path, &actual_path]) | ||
| .output() | ||
| { | ||
| Err(err) => { | ||
| self.fatal(&format!( | ||
| "failed to call custom diff command `{diff_command}`: {err}" | ||
| )); | ||
| } | ||
| Ok(output) => { | ||
| let output = String::from_utf8_lossy(&output.stdout); | ||
| print!("{output}"); | ||
| } | ||
| } | ||
| } else { | ||
| print!("{}", write_diff(expected, actual, 3)); | ||
| } | ||
| } | ||
| } | ||
|  | ||
| let mode = self.config.compare_mode.as_ref().map_or("", |m| m.to_str()); | ||
| let output_file = self | ||
| .output_base_name() | ||
| .with_extra_extension(self.revision.unwrap_or("")) | ||
| .with_extra_extension(mode) | ||
| .with_extra_extension(kind); | ||
|  | ||
| let mut files = vec![output_file]; | ||
| if self.config.bless { | ||
| } else { | ||
| // Delete non-revision .stderr/.stdout file if revisions are used. | ||
| // Without this, we'd just generate the new files and leave the old files around. | ||
| if self.revision.is_some() { | ||
| let old = | ||
| expected_output_path(self.testpaths, None, &self.config.compare_mode, kind); | ||
| expected_output_path(self.testpaths, None, &self.config.compare_mode, stream); | ||
| self.delete_file(&old); | ||
| } | ||
| files.push(expected_output_path( | ||
| self.testpaths, | ||
| self.revision, | ||
| &self.config.compare_mode, | ||
| kind, | ||
| )); | ||
| } | ||
|  | ||
| for output_file in &files { | ||
| if actual.is_empty() { | ||
| self.delete_file(output_file); | ||
| } else if let Err(err) = fs::write(&output_file, &actual) { | ||
| self.fatal(&format!( | ||
| "failed to write {} to `{}`: {}", | ||
| kind, | ||
| output_file.display(), | ||
| err, | ||
| )); | ||
| if let Err(err) = fs::write(&expected_path, &actual) { | ||
| self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}")); | ||
| } | ||
| println!("Blessing the {stream} of {test_name} in {expected_path:?}"); | ||
| } | ||
|  | ||
| println!("\nThe actual {0} differed from the expected {0}.", kind); | ||
| for output_file in files { | ||
| println!("Actual {} saved to {}", kind, output_file.display()); | ||
| } | ||
|         
                  jieyouxu marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| println!("\nThe actual {0} differed from the expected {0}.", stream); | ||
|  | ||
| if self.config.bless { 0 } else { 1 } | ||
| } | ||
|  | ||
|  | ||
      
      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.