@@ -2,7 +2,7 @@ import { spawn, execSync } from "child_process";
2
2
import chalk from "chalk" ;
3
3
import os from "os" ;
4
4
import { existsSync } from "fs" ;
5
- import { dirname } from "path" ;
5
+ import { dirname , join } from "path" ;
6
6
7
7
let ENV_VARS = { } ;
8
8
@@ -37,16 +37,17 @@ function setEnvVariables() {
37
37
// Helper function to run a command and capture output
38
38
function runCommand ( command ) {
39
39
try {
40
+ let env = {
41
+ SOPRINTLN : "1" ,
42
+ PATH : process . env . PATH ,
43
+ ...ENV_VARS ,
44
+ } ;
45
+ console . log ( "Running with env: " , env ) ;
40
46
const child = spawn ( command , [ ] , {
41
47
shell : true ,
42
48
stdio : [ "inherit" , "pipe" , "pipe" ] ,
43
- env : {
44
- SOPRINTLN : "1" ,
45
- PATH : process . env . PATH ,
46
- ...ENV_VARS ,
47
- } ,
49
+ env,
48
50
} ) ;
49
- console . log ( "Set ENV_VARS to: " , ENV_VARS ) ;
50
51
51
52
let output = "" ;
52
53
@@ -86,67 +87,85 @@ function checkFeatureMismatch(output) {
86
87
const testCases = [
87
88
{
88
89
name : "Tests pass (debug)" ,
89
- command : "cargo run --manifest-path test-crates/samplebin/Cargo.toml" ,
90
+ buildCommand :
91
+ "cargo build --manifest-path test-crates/samplebin/Cargo.toml" ,
92
+ runCommand : "./test-crates/samplebin/target/debug/samplebin" ,
90
93
expectedResult : "success" ,
91
94
} ,
92
95
{
93
96
name : "Tests pass (release)" ,
94
- command :
95
- "cargo run --manifest-path test-crates/samplebin/Cargo.toml --release" ,
97
+ buildCommand :
98
+ "cargo build --manifest-path test-crates/samplebin/Cargo.toml --release" ,
99
+ runCommand : "./test-crates/samplebin/target/release/samplebin" ,
96
100
expectedResult : "success" ,
97
101
} ,
98
102
{
99
103
name : "Bin stable, mod_a nightly (should fail)" ,
100
- command :
101
- "cargo +stable run --manifest-path test-crates/samplebin/Cargo.toml -- --channel:mod_a=nightly" ,
104
+ buildCommand :
105
+ "cargo +stable build --manifest-path test-crates/samplebin/Cargo.toml" ,
106
+ runCommand :
107
+ "./test-crates/samplebin/target/debug/samplebin --channel:mod_a=nightly" ,
102
108
expectedResult : "fail" ,
103
109
checkFeatureMismatch : true ,
104
110
} ,
105
111
{
106
112
name : "Bin nightly, mod_a stable (should fail)" ,
107
- command :
108
- "cargo +nightly run --manifest-path test-crates/samplebin/Cargo.toml -- --channel:mod_a=stable" ,
113
+ buildCommand :
114
+ "cargo +nightly build --manifest-path test-crates/samplebin/Cargo.toml" ,
115
+ runCommand :
116
+ "./test-crates/samplebin/target/debug/samplebin --channel:mod_a=stable" ,
109
117
expectedResult : "fail" ,
110
118
checkFeatureMismatch : true ,
111
119
} ,
112
120
{
113
121
name : "All nightly (should work)" ,
114
- command :
115
- "cargo +nightly run --manifest-path test-crates/samplebin/Cargo.toml -- --channel:mod_a=nightly --channel:mod_b=nightly" ,
122
+ buildCommand :
123
+ "cargo +nightly build --manifest-path test-crates/samplebin/Cargo.toml" ,
124
+ runCommand :
125
+ "./test-crates/samplebin/target/debug/samplebin --channel:mod_a=nightly --channel:mod_b=nightly" ,
116
126
expectedResult : "success" ,
117
127
} ,
118
128
{
119
129
name : "Bin has mokio-timer feature (should fail)" ,
120
- command :
121
- "cargo run --features=exports/mokio-timer --manifest-path test-crates/samplebin/Cargo.toml" ,
130
+ buildCommand :
131
+ "cargo build --features=exports/mokio-timer --manifest-path test-crates/samplebin/Cargo.toml" ,
132
+ runCommand : "./test-crates/samplebin/target/debug/samplebin" ,
122
133
expectedResult : "fail" ,
123
134
checkFeatureMismatch : true ,
124
135
} ,
125
136
{
126
137
name : "mod_a has mokio-timer feature (should fail)" ,
127
- command :
128
- "cargo run --manifest-path test-crates/mod_a/Cargo.toml -- --features:mod_a=mokio/timer" ,
138
+ buildCommand :
139
+ "cargo build --manifest-path test-crates/samplebin/Cargo.toml" ,
140
+ runCommand :
141
+ "./test-crates/samplebin/target/debug/samplebin --features:mod_a=mokio/timer" ,
129
142
expectedResult : "fail" ,
130
143
checkFeatureMismatch : true ,
131
144
} ,
132
145
{
133
146
name : "mod_b has mokio-timer feature (should fail)" ,
134
- command :
135
- "cargo run --manifest-path test-crates/mod_b/Cargo.toml -- --features:mod_b=mokio/timer" ,
147
+ buildCommand :
148
+ "cargo build --manifest-path test-crates/samplebin/Cargo.toml" ,
149
+ runCommand :
150
+ "./test-crates/samplebin/target/debug/samplebin --features:mod_b=mokio/timer" ,
136
151
expectedResult : "fail" ,
137
152
checkFeatureMismatch : true ,
138
153
} ,
139
154
{
140
155
name : "all mods have mokio-timer feature (should fail)" ,
141
- command :
142
- "cargo run --manifest-path test-crates/samplebin/Cargo.toml -- --features:mod_a=mokio/timer --features:mod_b=mokio/timer" ,
156
+ buildCommand :
157
+ "cargo build --manifest-path test-crates/samplebin/Cargo.toml" ,
158
+ runCommand :
159
+ "./test-crates/samplebin/target/debug/samplebin --features:mod_a=mokio/timer --features:mod_b=mokio/timer" ,
143
160
expectedResult : "fail" ,
144
161
checkFeatureMismatch : true ,
145
162
} ,
146
163
{
147
164
name : "bin and mods have mokio-timer feature (should work)" ,
148
- command :
149
- "cargo run --features=exports/mokio-timer --manifest-path test-crates/samplebin/Cargo.toml -- --features:mod_a=mokio/timer --features:mod_b=mokio/timer" ,
165
+ buildCommand :
166
+ "cargo build --features=exports/mokio-timer --manifest-path test-crates/samplebin/Cargo.toml" ,
167
+ runCommand :
168
+ "./test-crates/samplebin/target/debug/samplebin --features:mod_a=mokio/timer --features:mod_b=mokio/timer" ,
150
169
expectedResult : "success" ,
151
170
} ,
152
171
] ;
@@ -182,7 +201,16 @@ async function runTests() {
182
201
console . log ( chalk . blue ( "Running tests..." ) ) ;
183
202
for ( const [ index , test ] of testCases . entries ( ) ) {
184
203
console . log ( chalk . yellow ( `\nRunning test ${ index + 1 } : ${ test . name } ` ) ) ;
185
- const { success, output } = await runCommand ( test . command ) ;
204
+
205
+ console . log ( chalk . cyan ( "Building..." ) ) ;
206
+ const buildResult = await runCommand ( test . buildCommand ) ;
207
+ if ( ! buildResult . success ) {
208
+ console . log ( chalk . red ( "Build failed. Exiting tests." ) ) ;
209
+ process . exit ( 1 ) ;
210
+ }
211
+
212
+ console . log ( chalk . cyan ( "Running..." ) ) ;
213
+ const { success, output } = await runCommand ( test . runCommand ) ;
186
214
187
215
if ( test . expectedResult === "success" && success ) {
188
216
console . log ( chalk . green ( "Test passed as expected." ) ) ;
@@ -197,15 +225,19 @@ async function runTests() {
197
225
"Test failed, but not with the expected feature mismatch error." ,
198
226
) ,
199
227
) ;
228
+ process . exit ( 1 ) ;
200
229
}
201
230
} else {
202
231
console . log (
203
232
chalk . red (
204
233
`Test result unexpected. Expected ${ test . expectedResult } , but got ${ success ? "success" : "failure" } .` ,
205
234
) ,
206
235
) ;
236
+ process . exit ( 1 ) ;
207
237
}
208
238
}
239
+
240
+ console . log ( chalk . green ( "All tests passed successfully." ) ) ;
209
241
}
210
242
211
243
// Run the tests
0 commit comments