@@ -2,7 +2,7 @@ mod full {
2
2
use log:: { log_enabled, Level } ;
3
3
use std:: {
4
4
env,
5
- fs:: File ,
5
+ fs:: { read_to_string , File } ,
6
6
io:: { BufRead , Write } ,
7
7
path:: Path ,
8
8
process:: { Command , Stdio } ,
@@ -39,13 +39,6 @@ mod full {
39
39
40
40
let output = cmd. output ( ) . expect ( "could not run cargo semver" ) ;
41
41
42
- assert_eq ! (
43
- output. status. success( ) ,
44
- expected_result,
45
- "cargo-semver returned unexpected exit status {}" ,
46
- output. status
47
- ) ;
48
-
49
42
// Choose solution depending on the platform
50
43
let file_ext = if cfg ! ( target_os = "macos" ) {
51
44
"osx"
@@ -58,20 +51,17 @@ mod full {
58
51
return ;
59
52
} ;
60
53
61
- let filename = Path :: new ( "tests/full_cases" ) . join ( format ! (
54
+ let filename = format ! (
62
55
"{}-{}-{}.{}" ,
63
56
crate_name, old_version, new_version, file_ext
64
- ) ) ;
65
-
66
- assert ! (
67
- filename. exists( ) ,
68
- "file `{}` does not exist" ,
69
- filename. display( )
70
57
) ;
71
58
72
- let mut file = File :: create ( & filename ) . expect ( "could not create output file" ) ;
59
+ let expected_path = Path :: new ( "tests/full_cases" ) . join ( & filename ) ;
73
60
74
- for line in output
61
+ let expected_output =
62
+ read_to_string ( & expected_path) . expect ( "could not read expected output from file" ) ;
63
+
64
+ let new_output = output
75
65
. stdout
76
66
. lines ( )
77
67
. chain ( output. stderr . lines ( ) )
@@ -81,34 +71,42 @@ mod full {
81
71
!line. starts_with ( "version bump" ) &&
82
72
// ...unless debugging is enabled
83
73
!log_enabled ! ( Level :: Debug ) )
84
- {
85
- // sanitize paths for reproducibility
86
- let output = match line. find ( "-->" ) {
87
- Some ( idx) => {
88
- let ( start, end) = line. split_at ( idx) ;
89
- match end. find ( crate_name) {
90
- Some ( idx) => format ! ( "{}--> {}" , start, end. split_at( idx) . 1 ) ,
91
- None => line,
74
+ . map ( |line| {
75
+ // sanitize paths for reproducibility
76
+ ( match line. find ( "-->" ) {
77
+ Some ( idx) => {
78
+ let ( start, end) = line. split_at ( idx) ;
79
+ match end. find ( crate_name) {
80
+ Some ( idx) => format ! ( "{}--> {}" , start, end. split_at( idx) . 1 ) ,
81
+ None => line,
82
+ }
92
83
}
93
- }
94
- None => line,
95
- } ;
96
- writeln ! ( file, "{}" , output) . expect ( "error writing to output file" ) ;
97
- }
84
+ None => line,
85
+ } ) + "\n "
86
+ } )
87
+ . collect :: < String > ( ) ;
98
88
99
- let git_result = Command :: new ( "git" )
100
- . args ( & [
101
- "diff" ,
102
- "--ignore-space-at-eol" ,
103
- "--exit-code" ,
104
- filename. to_str ( ) . unwrap ( ) ,
105
- ] )
106
- . env ( "PAGER" , "" )
107
- . status ( )
108
- . expect ( "could not run git diff" )
109
- . success ( ) ;
89
+ if expected_output != new_output {
90
+ eprintln ! ( "cargo-semver failed to produce the expected output" ) ;
110
91
111
- assert ! ( git_result, "git reports unexpected diff" ) ;
92
+ let new_path = Path :: new ( & env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( filename) ;
93
+ let mut new_file = File :: create ( & new_path) . unwrap ( ) ;
94
+ new_file. write_all ( new_output. as_bytes ( ) ) . unwrap ( ) ;
95
+
96
+ eprintln ! (
97
+ "For details, try this command: \n \n diff {} {}\n \n " ,
98
+ expected_path. display( ) ,
99
+ new_path. display( )
100
+ ) ;
101
+ panic ! ( "unexpected output diff" ) ;
102
+ }
103
+
104
+ assert_eq ! (
105
+ output. status. success( ) ,
106
+ expected_result,
107
+ "cargo-semver returned unexpected exit status {}" ,
108
+ output. status
109
+ ) ;
112
110
}
113
111
114
112
macro_rules! full_test {
0 commit comments