1
1
#[ test]
2
2
#[ cfg_attr( debug_assertions, ignore) ]
3
3
fn release ( ) {
4
+ let root = snapbox:: dir:: DirRoot :: mutable_temp ( ) . unwrap ( ) ;
5
+ let root_path = root. path ( ) . unwrap ( ) ;
6
+
7
+ #[ cfg( unix) ]
8
+ let envs = [ ( "TMPDIR" , root_path) ] ;
9
+ #[ cfg( not( unix) ) ]
10
+ let envs: [ ( & str , & str ) ; 0 ] = [ ] ;
11
+
4
12
snapbox:: cmd:: Command :: new ( snapbox:: cmd:: cargo_bin!( "single-panic-test" ) )
13
+ . envs ( envs)
5
14
. assert ( )
6
15
. stderr_eq ( snapbox:: str![ [ r#"
7
16
Well, this is embarrassing.
@@ -18,12 +27,59 @@ Thank you kindly!
18
27
19
28
"# ] ] )
20
29
. code ( 101 ) ;
30
+
31
+ #[ cfg( unix) ]
32
+ {
33
+ let mut files = root_path
34
+ . read_dir ( )
35
+ . unwrap ( )
36
+ . map ( |e| {
37
+ let e = e. unwrap ( ) ;
38
+ let path = e. path ( ) ;
39
+ let content = std:: fs:: read_to_string ( & path) ;
40
+ ( path, content)
41
+ } )
42
+ . collect :: < Vec < _ > > ( ) ;
43
+ assert_eq ! ( files. len( ) , 1 , "{files:?}" ) ;
44
+ let ( _, report) = files. pop ( ) . unwrap ( ) ;
45
+ let report = report. unwrap ( ) ;
46
+ snapbox:: assert_data_eq!(
47
+ report,
48
+ snapbox:: str ![ [ r#"
49
+ "name" = "single-panic-test"
50
+ "operating_system" = "[..]"
51
+ "crate_version" = "0.1.0"
52
+ "explanation" = """
53
+ Panic occurred in file 'tests/single-panic/src/main.rs' at line [..]
54
+ """
55
+ "cause" = "OMG EVERYTHING IS ON FIRE!!!"
56
+ "method" = "Panic"
57
+ "backtrace" = """
58
+
59
+ 0: [..]
60
+ ...
61
+ 8: [..]"""
62
+
63
+ "# ] ]
64
+ ) ;
65
+ }
66
+
67
+ root. close ( ) . unwrap ( ) ;
21
68
}
22
69
23
70
#[ test]
24
71
#[ cfg_attr( not( debug_assertions) , ignore) ]
25
72
fn debug ( ) {
73
+ let root = snapbox:: dir:: DirRoot :: mutable_temp ( ) . unwrap ( ) ;
74
+ let root_path = root. path ( ) . unwrap ( ) ;
75
+
76
+ #[ cfg( unix) ]
77
+ let envs = [ ( "TMPDIR" , root_path) ] ;
78
+ #[ cfg( not( unix) ) ]
79
+ let envs: [ ( & str , & str ) ; 0 ] = [ ] ;
80
+
26
81
snapbox:: cmd:: Command :: new ( snapbox:: cmd:: cargo_bin!( "single-panic-test" ) )
82
+ . envs ( envs)
27
83
. assert ( )
28
84
. stderr_eq ( snapbox:: str![ [ r#"
29
85
thread 'main' panicked at tests/single-panic/src/main.rs:7:5:
@@ -32,4 +88,21 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
32
88
33
89
"# ] ] )
34
90
. code ( 101 ) ;
91
+
92
+ #[ cfg( unix) ]
93
+ {
94
+ let files = root_path
95
+ . read_dir ( )
96
+ . unwrap ( )
97
+ . map ( |e| {
98
+ let e = e. unwrap ( ) ;
99
+ let path = e. path ( ) ;
100
+ let content = std:: fs:: read_to_string ( & path) ;
101
+ ( path, content)
102
+ } )
103
+ . collect :: < Vec < _ > > ( ) ;
104
+ assert ! ( files. is_empty( ) , "{files:?}" ) ;
105
+ }
106
+
107
+ root. close ( ) . unwrap ( ) ;
35
108
}
0 commit comments