@@ -74,6 +74,12 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
74
74
requires_reason = true ;
75
75
set_ignore ! ( is_not_nightly, "requires nightly" ) ;
76
76
}
77
+ "requires_rustup_stable" => {
78
+ set_ignore ! (
79
+ !has_rustup_stable( ) ,
80
+ "rustup or stable toolchain not installed"
81
+ ) ;
82
+ }
77
83
s if s. starts_with ( "requires_" ) => {
78
84
let command = & s[ 9 ..] ;
79
85
set_ignore ! ( !has_command( command) , "{command} not installed" ) ;
@@ -204,29 +210,27 @@ fn version() -> (u32, bool) {
204
210
unsafe { VERSION }
205
211
}
206
212
207
- fn has_command ( command : & str ) -> bool {
208
- let output = match Command :: new ( command) . arg ( "--version" ) . output ( ) {
213
+ fn check_command ( command_name : & str , args : & [ & str ] ) -> bool {
214
+ let mut command = Command :: new ( command_name) ;
215
+ command. args ( args) ;
216
+ let output = match command. output ( ) {
209
217
Ok ( output) => output,
210
218
Err ( e) => {
211
219
// * hg is not installed on GitHub macOS or certain constrained
212
220
// environments like Docker. Consider installing it if Cargo
213
221
// gains more hg support, but otherwise it isn't critical.
214
222
// * lldb is not pre-installed on Ubuntu and Windows, so skip.
215
- if is_ci ( ) && ![ "hg" , "lldb" ] . contains ( & command) {
216
- panic ! (
217
- "expected command `{}` to be somewhere in PATH: {}" ,
218
- command, e
219
- ) ;
223
+ if is_ci ( ) && !matches ! ( command_name, "hg" | "lldb" ) {
224
+ panic ! ( "expected command `{command_name}` to be somewhere in PATH: {e}" , ) ;
220
225
}
221
226
return false ;
222
227
}
223
228
} ;
224
229
if !output. status . success ( ) {
225
230
panic ! (
226
- "expected command `{}` to be runnable, got error {}:\n \
231
+ "expected command `{command_name }` to be runnable, got error {}:\n \
227
232
stderr:{}\n \
228
233
stdout:{}\n ",
229
- command,
230
234
output. status,
231
235
String :: from_utf8_lossy( & output. stderr) ,
232
236
String :: from_utf8_lossy( & output. stdout)
@@ -235,6 +239,18 @@ fn has_command(command: &str) -> bool {
235
239
true
236
240
}
237
241
242
+ fn has_command ( command : & str ) -> bool {
243
+ check_command ( command, & [ "--version" ] )
244
+ }
245
+
246
+ fn has_rustup_stable ( ) -> bool {
247
+ if option_env ! ( "CARGO_TEST_DISABLE_NIGHTLY" ) . is_some ( ) {
248
+ // This cannot run on rust-lang/rust CI due to the lack of rustup.
249
+ return false ;
250
+ }
251
+ check_command ( "cargo" , & [ "+stable" , "--version" ] )
252
+ }
253
+
238
254
/// Whether or not this running in a Continuous Integration environment.
239
255
fn is_ci ( ) -> bool {
240
256
// Consider using `tracked_env` instead of option_env! when it is stabilized.
0 commit comments