11use super :: AutoCfg ;
22use std:: env;
33use std:: path:: Path ;
4+ use std:: process:: Command ;
5+ use std:: str;
46
57impl AutoCfg {
68 fn core_std ( & self , path : & str ) -> String {
@@ -22,6 +24,32 @@ impl AutoCfg {
2224 None => Self :: with_dir ( "target" ) ,
2325 }
2426 }
27+
28+ fn assert_nightly ( & self , probe_result : bool ) {
29+ // Get rustc's verbose version
30+ let output = Command :: new ( & self . rustc )
31+ . args ( & [ "--version" , "--verbose" ] )
32+ . output ( )
33+ . unwrap ( ) ;
34+ if !output. status . success ( ) {
35+ panic ! ( "could not execute rustc" )
36+ }
37+ let output = str:: from_utf8 ( & output. stdout ) . unwrap ( ) ;
38+
39+ // Find the release line in the verbose version output.
40+ let release = match output. lines ( ) . find ( |line| line. starts_with ( "release: " ) ) {
41+ Some ( line) => & line[ "release: " . len ( ) ..] ,
42+ None => panic ! ( "could not find rustc release" ) ,
43+ } ;
44+
45+ // Check for nightly channel info, e.g. "-nightly", "-dev"
46+ let nightly = match release. find ( '-' ) {
47+ Some ( i) => & release[ i..] == "-nightly" || & release[ i..] == "-dev" ,
48+ None => false ,
49+ } ;
50+
51+ assert_eq ! ( nightly, probe_result) ;
52+ }
2553}
2654
2755#[ test]
@@ -133,6 +161,17 @@ fn probe_constant() {
133161 ac. assert_min ( 1 , 39 , ac. probe_constant ( r#""test".len()"# ) ) ;
134162}
135163
164+ #[ test]
165+ fn prope_feature ( ) {
166+ let ac = AutoCfg :: for_test ( ) . unwrap ( ) ;
167+ // an empty #![features()] has no effect
168+ assert ! ( ac. probe_features( & [ ] , "" ) ) ;
169+ // stabilized feature succeeds
170+ ac. assert_nightly ( ac. probe_features ( & [ "rust1" ] , "" ) ) ;
171+ // fake feature fails
172+ ac. assert_nightly ( !ac. probe_features ( & [ "RUSTC_DONT_MAKE_ME_A_LIAR" ] , "" ) ) ;
173+ }
174+
136175#[ test]
137176fn dir_does_not_contain_target ( ) {
138177 assert ! ( !super :: dir_contains_target(
0 commit comments