@@ -10,18 +10,129 @@ use virolution::args::Args;
10
10
use virolution:: runner:: Runner ;
11
11
12
12
fn main ( ) {
13
+ let args = Args :: parse ( ) ;
14
+
13
15
if cfg ! ( feature = "parallel" ) {
14
16
println ! ( "Running in parallel mode." ) ;
15
17
} else {
16
18
println ! ( "Running in serial mode." ) ;
17
19
}
18
20
19
- let args = Args :: parse ( ) ;
20
-
21
21
let mut runner = Runner :: new ( args) . unwrap_or_else ( |err| {
22
22
eprintln ! ( "Unable to init simulation: {err}." ) ;
23
23
std:: process:: exit ( 1 ) ;
24
24
} ) ;
25
25
26
26
runner. start ( ) ;
27
27
}
28
+
29
+ /// TODO: These tests should run for multiple feature flags
30
+ #[ cfg( test) ]
31
+ mod tests {
32
+ use std:: process:: Command ;
33
+
34
+ struct Cleanup < ' a > {
35
+ dir : & ' a str ,
36
+ }
37
+
38
+ impl < ' a > Drop for Cleanup < ' a > {
39
+ fn drop ( & mut self ) {
40
+ std:: fs:: remove_dir_all ( self . dir ) . unwrap ( ) ;
41
+ }
42
+ }
43
+
44
+ /// Test invocation of program for singlehost setup with 1 generation
45
+ #[ test]
46
+ fn test_singlehost ( ) {
47
+ let tmp_dir = ".tmp_singlehost" ;
48
+ let _cleanup = Cleanup { dir : tmp_dir } ;
49
+ let output = Command :: new ( "cargo" )
50
+ . args ( [
51
+ "run" ,
52
+ "--" ,
53
+ "--disable-progress-bar" ,
54
+ "--settings" ,
55
+ "test/singlehost/singlehost.yaml" ,
56
+ "--sequence" ,
57
+ "test/singlehost/ref.fasta" ,
58
+ "--generations" ,
59
+ "1" ,
60
+ "--n-compartments" ,
61
+ "2" ,
62
+ "--outdir" ,
63
+ tmp_dir,
64
+ ] )
65
+ . output ( )
66
+ . expect ( "Failed to execute command" ) ;
67
+
68
+ assert ! ( output. status. success( ) ) ;
69
+
70
+ // Check if output files are created
71
+ assert ! ( std:: path:: Path :: new( & format!( "{}/fitness_table_0.npy" , tmp_dir) ) . exists( ) ) ;
72
+ assert ! ( std:: path:: Path :: new( & format!( "{}/virolution.log" , tmp_dir) ) . exists( ) ) ;
73
+ }
74
+
75
+ /// Test invocation of program for multihost setup with 1 generation
76
+ #[ test]
77
+ fn test_multihost ( ) {
78
+ let tmp_dir = ".tmp_multihost" ;
79
+ let _cleanup = Cleanup { dir : tmp_dir } ;
80
+
81
+ let output = Command :: new ( "cargo" )
82
+ . args ( [
83
+ "run" ,
84
+ "--" ,
85
+ "--disable-progress-bar" ,
86
+ "--settings" ,
87
+ "test/multihost/multihost.yaml" ,
88
+ "--sequence" ,
89
+ "test/multihost/ref.fasta" ,
90
+ "--generations" ,
91
+ "1" ,
92
+ "--n-compartments" ,
93
+ "2" ,
94
+ "--outdir" ,
95
+ tmp_dir,
96
+ ] )
97
+ . output ( )
98
+ . expect ( "Failed to execute command" ) ;
99
+
100
+ assert ! ( output. status. success( ) ) ;
101
+
102
+ // Check if output files are created
103
+ assert ! ( std:: path:: Path :: new( & format!( "{}/fitness_table_0.npy" , tmp_dir) ) . exists( ) ) ;
104
+ assert ! ( std:: path:: Path :: new( & format!( "{}/fitness_table_1.npy" , tmp_dir) ) . exists( ) ) ;
105
+ assert ! ( std:: path:: Path :: new( & format!( "{}/virolution.log" , tmp_dir) ) . exists( ) ) ;
106
+ }
107
+
108
+ /// Test invocation of program for epistasis setup with 1 generation
109
+ #[ test]
110
+ fn test_epistasis ( ) {
111
+ let tmp_dir = ".tmp_epistasis" ;
112
+ let output = Command :: new ( "cargo" )
113
+ . args ( [
114
+ "run" ,
115
+ "--" ,
116
+ "--disable-progress-bar" ,
117
+ "--settings" ,
118
+ "test/epistasis/epistasis.yaml" ,
119
+ "--sequence" ,
120
+ "test/epistasis/ref.fasta" ,
121
+ "--generations" ,
122
+ "1" ,
123
+ "--n-compartments" ,
124
+ "2" ,
125
+ "--outdir" ,
126
+ tmp_dir,
127
+ ] )
128
+ . output ( )
129
+ . expect ( "Failed to execute command" ) ;
130
+
131
+ assert ! ( output. status. success( ) ) ;
132
+
133
+ // Check if output files are created
134
+ assert ! ( std:: path:: Path :: new( & format!( "{}/fitness_table_0.npy" , tmp_dir) ) . exists( ) ) ;
135
+ assert ! ( std:: path:: Path :: new( & format!( "{}/epistasis_table_0.npy" , tmp_dir) ) . exists( ) ) ;
136
+ assert ! ( std:: path:: Path :: new( & format!( "{}/virolution.log" , tmp_dir) ) . exists( ) ) ;
137
+ }
138
+ }
0 commit comments