@@ -8,6 +8,7 @@ use crate::common::{CompareMode, FailMode, PassMode};
8
8
use crate :: common:: { Config , TestPaths } ;
9
9
use crate :: common:: { Pretty , RunPassValgrind } ;
10
10
use crate :: common:: { UI_RUN_STDERR , UI_RUN_STDOUT } ;
11
+ use crate :: compute_diff:: write_diff;
11
12
use crate :: errors:: { self , Error , ErrorKind } ;
12
13
use crate :: header:: TestProps ;
13
14
use crate :: json;
@@ -18,7 +19,7 @@ use regex::{Captures, Regex};
18
19
use rustfix:: { apply_suggestions, get_suggestions_from_json, Filter } ;
19
20
20
21
use std:: collections:: hash_map:: DefaultHasher ;
21
- use std:: collections:: { HashMap , HashSet , VecDeque } ;
22
+ use std:: collections:: { HashMap , HashSet } ;
22
23
use std:: env;
23
24
use std:: ffi:: { OsStr , OsString } ;
24
25
use std:: fs:: { self , create_dir_all, File , OpenOptions } ;
@@ -100,111 +101,6 @@ pub fn get_lib_name(lib: &str, dylib: bool) -> String {
100
101
}
101
102
}
102
103
103
- #[ derive( Debug , PartialEq ) ]
104
- pub enum DiffLine {
105
- Context ( String ) ,
106
- Expected ( String ) ,
107
- Resulting ( String ) ,
108
- }
109
-
110
- #[ derive( Debug , PartialEq ) ]
111
- pub struct Mismatch {
112
- pub line_number : u32 ,
113
- pub lines : Vec < DiffLine > ,
114
- }
115
-
116
- impl Mismatch {
117
- fn new ( line_number : u32 ) -> Mismatch {
118
- Mismatch { line_number, lines : Vec :: new ( ) }
119
- }
120
- }
121
-
122
- // Produces a diff between the expected output and actual output.
123
- pub fn make_diff ( expected : & str , actual : & str , context_size : usize ) -> Vec < Mismatch > {
124
- let mut line_number = 1 ;
125
- let mut context_queue: VecDeque < & str > = VecDeque :: with_capacity ( context_size) ;
126
- let mut lines_since_mismatch = context_size + 1 ;
127
- let mut results = Vec :: new ( ) ;
128
- let mut mismatch = Mismatch :: new ( 0 ) ;
129
-
130
- for result in diff:: lines ( expected, actual) {
131
- match result {
132
- diff:: Result :: Left ( str) => {
133
- if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
134
- results. push ( mismatch) ;
135
- mismatch = Mismatch :: new ( line_number - context_queue. len ( ) as u32 ) ;
136
- }
137
-
138
- while let Some ( line) = context_queue. pop_front ( ) {
139
- mismatch. lines . push ( DiffLine :: Context ( line. to_owned ( ) ) ) ;
140
- }
141
-
142
- mismatch. lines . push ( DiffLine :: Expected ( str. to_owned ( ) ) ) ;
143
- line_number += 1 ;
144
- lines_since_mismatch = 0 ;
145
- }
146
- diff:: Result :: Right ( str) => {
147
- if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
148
- results. push ( mismatch) ;
149
- mismatch = Mismatch :: new ( line_number - context_queue. len ( ) as u32 ) ;
150
- }
151
-
152
- while let Some ( line) = context_queue. pop_front ( ) {
153
- mismatch. lines . push ( DiffLine :: Context ( line. to_owned ( ) ) ) ;
154
- }
155
-
156
- mismatch. lines . push ( DiffLine :: Resulting ( str. to_owned ( ) ) ) ;
157
- lines_since_mismatch = 0 ;
158
- }
159
- diff:: Result :: Both ( str, _) => {
160
- if context_queue. len ( ) >= context_size {
161
- let _ = context_queue. pop_front ( ) ;
162
- }
163
-
164
- if lines_since_mismatch < context_size {
165
- mismatch. lines . push ( DiffLine :: Context ( str. to_owned ( ) ) ) ;
166
- } else if context_size > 0 {
167
- context_queue. push_back ( str) ;
168
- }
169
-
170
- line_number += 1 ;
171
- lines_since_mismatch += 1 ;
172
- }
173
- }
174
- }
175
-
176
- results. push ( mismatch) ;
177
- results. remove ( 0 ) ;
178
-
179
- results
180
- }
181
-
182
- fn write_diff ( expected : & str , actual : & str , context_size : usize ) -> String {
183
- use std:: fmt:: Write ;
184
- let mut output = String :: new ( ) ;
185
- let diff_results = make_diff ( expected, actual, context_size) ;
186
- for result in diff_results {
187
- let mut line_number = result. line_number ;
188
- for line in result. lines {
189
- match line {
190
- DiffLine :: Expected ( e) => {
191
- writeln ! ( output, "-\t {}" , e) . unwrap ( ) ;
192
- line_number += 1 ;
193
- }
194
- DiffLine :: Context ( c) => {
195
- writeln ! ( output, "{}\t {}" , line_number, c) . unwrap ( ) ;
196
- line_number += 1 ;
197
- }
198
- DiffLine :: Resulting ( r) => {
199
- writeln ! ( output, "+\t {}" , r) . unwrap ( ) ;
200
- }
201
- }
202
- }
203
- writeln ! ( output) . unwrap ( ) ;
204
- }
205
- output
206
- }
207
-
208
104
pub fn run ( config : Config , testpaths : & TestPaths , revision : Option < & str > ) {
209
105
match & * config. target {
210
106
"arm-linux-androideabi"
0 commit comments