1
+ use assert_cmd:: prelude:: * ;
1
2
use common:: CommandCraterExt ;
2
3
use difference:: Changeset ;
3
4
use rand:: { self , distributions:: Alphanumeric , Rng } ;
4
5
use serde_json:: { self , Value } ;
6
+ use std:: env;
5
7
use std:: path:: PathBuf ;
6
8
use std:: process:: Command ;
7
9
8
- fn execute ( ex : & str , crate_select : & str ) {
10
+ trait CommandMinicraterExt {
11
+ fn minicrater_exec ( & mut self ) ;
12
+ }
13
+
14
+ impl CommandMinicraterExt for Command {
15
+ fn minicrater_exec ( & mut self ) {
16
+ if env:: var_os ( "MINICRATER_SHOW_OUTPUT" ) . is_some ( ) {
17
+ assert ! ( self . status( ) . unwrap( ) . success( ) ) ;
18
+ } else {
19
+ self . assert ( ) . success ( ) ;
20
+ }
21
+ }
22
+ }
23
+
24
+ fn execute ( ex : & str , crate_select : & str , multithread : bool ) {
9
25
let ex_dir = PathBuf :: from ( "tests" ) . join ( "minicrater" ) . join ( ex) ;
10
26
let config_file = ex_dir. join ( "config.toml" ) ;
11
27
let expected_file = ex_dir. join ( "results.expected.json" ) ;
12
28
let actual_file = ex_dir. join ( "results.actual.json" ) ;
13
29
30
+ let threads_count = if multithread { :: num_cpus:: get ( ) } else { 1 } ;
31
+
14
32
let report_dir = :: tempfile:: tempdir ( ) . expect ( "failed to create report dir" ) ;
15
33
let ex_arg = format ! (
16
34
"--ex=minicrater-{}-{}" ,
@@ -22,54 +40,48 @@ fn execute(ex: &str, crate_select: &str) {
22
40
) ;
23
41
24
42
// Create local list in the temp work dir
25
- let out = Command :: crater ( )
43
+ Command :: crater ( )
26
44
. args ( & [ "create-lists" , "local" ] )
27
45
. env ( "CRATER_CONFIG" , & config_file)
28
- . status ( )
29
- . unwrap ( ) ;
30
- assert ! ( out. success( ) ) ;
46
+ . minicrater_exec ( ) ;
31
47
32
48
// Define the experiment
33
- let out = Command :: crater ( )
49
+ Command :: crater ( )
34
50
. args ( & [
35
51
"define-ex" ,
36
52
& ex_arg,
37
53
"stable" ,
38
54
"beta" ,
39
55
& format ! ( "--crate-select={}" , crate_select) ,
40
56
] ) . env ( "CRATER_CONFIG" , & config_file)
41
- . status ( )
42
- . unwrap ( ) ;
43
- assert ! ( out. success( ) ) ;
57
+ . minicrater_exec ( ) ;
44
58
45
59
// Execute the experiment
46
- let out = Command :: crater ( )
47
- . args ( & [ "run-graph" , & ex_arg] )
48
- . env ( "CRATER_CONFIG" , & config_file)
49
- . status ( )
50
- . unwrap ( ) ;
51
- assert ! ( out. success( ) ) ;
60
+ Command :: crater ( )
61
+ . args ( & [
62
+ "run-graph" ,
63
+ & ex_arg,
64
+ "--threads" ,
65
+ & threads_count. to_string ( ) ,
66
+ ] ) . env ( "CRATER_CONFIG" , & config_file)
67
+ . minicrater_exec ( ) ;
52
68
53
69
// Generate the report
54
- let out = Command :: crater ( )
70
+ Command :: crater ( )
55
71
. args ( & [ "gen-report" , & ex_arg] )
56
72
. env ( "CRATER_CONFIG" , & config_file)
57
73
. arg ( report_dir. path ( ) )
58
- . status ( )
59
- . unwrap ( ) ;
60
- assert ! ( out. success( ) ) ;
74
+ . minicrater_exec ( ) ;
61
75
62
76
// Read the JSON report
63
77
let json_report = :: std:: fs:: read ( report_dir. path ( ) . join ( "results.json" ) )
64
78
. expect ( "failed to read json report" ) ;
65
79
66
80
// Delete the experiment
67
- let out = Command :: crater ( )
81
+ Command :: crater ( )
68
82
. args ( & [ "delete-ex" , & ex_arg] )
69
83
. env ( "CRATER_CONFIG" , & config_file)
70
- . status ( )
71
- . unwrap ( ) ;
72
- assert ! ( out. success( ) ) ;
84
+ . minicrater_exec ( ) ;
73
85
74
86
// Load the generated JSON report
75
87
let parsed_report: Value = serde_json:: from_slice ( & json_report) . expect ( "invalid json report" ) ;
@@ -105,12 +117,18 @@ fn execute(ex: &str, crate_select: &str) {
105
117
106
118
#[ ignore]
107
119
#[ test]
108
- fn run_small ( ) {
109
- execute ( "small" , "demo" ) ;
120
+ fn single_thread_small ( ) {
121
+ execute ( "small" , "demo" , false ) ;
122
+ }
123
+
124
+ #[ ignore]
125
+ #[ test]
126
+ fn single_thread_full ( ) {
127
+ execute ( "full" , "local" , false ) ;
110
128
}
111
129
112
130
#[ ignore]
113
131
#[ test]
114
- fn run_full ( ) {
115
- execute ( "full" , "local" ) ;
132
+ fn multi_thread_full ( ) {
133
+ execute ( "full" , "local" , true ) ;
116
134
}
0 commit comments