@@ -852,96 +852,99 @@ fn clang_android() {
852
852
}
853
853
}
854
854
855
- #[ test]
856
855
#[ cfg( windows) ]
857
- fn msvc_prefer_clang_cl_over_msvc_disabled_by_default ( ) {
858
- reset_env ( ) ;
856
+ #[ cfg( not( feature = "disable-clang-cl-tests" ) ) ]
857
+ mod msvc_clang_cl_tests {
858
+ use super :: { reset_env, Test } ;
859
859
860
- let test = Test :: msvc_autodetect ( ) ;
860
+ #[ test]
861
+ fn msvc_prefer_clang_cl_over_msvc_disabled_by_default ( ) {
862
+ reset_env ( ) ;
861
863
862
- // When prefer_clang_cl_over_msvc is not called (default false), should use MSVC
863
- let compiler = test
864
- . gcc ( )
865
- . try_get_compiler ( )
866
- . expect ( "Failed to get compiler" ) ;
867
-
868
- // By default, should be using MSVC (cl.exe) and NOT clang-cl
869
- assert ! ( compiler. is_like_msvc( ) , "Should use MSVC by default" ) ;
870
- assert ! (
871
- !compiler. is_like_clang_cl( ) ,
872
- "Should not use clang-cl by default"
873
- ) ;
874
- }
864
+ let test = Test :: msvc_autodetect ( ) ;
875
865
876
- #[ test]
877
- #[ cfg( windows) ]
878
- fn msvc_prefer_clang_cl_over_msvc_enabled ( ) {
879
- reset_env ( ) ;
866
+ // When prefer_clang_cl_over_msvc is not called (default false), should use MSVC
867
+ let compiler = test
868
+ . gcc ( )
869
+ . try_get_compiler ( )
870
+ . expect ( "Failed to get compiler" ) ;
871
+
872
+ // By default, should be using MSVC (cl.exe) and NOT clang-cl
873
+ assert ! ( compiler. is_like_msvc( ) , "Should use MSVC by default" ) ;
874
+ assert ! (
875
+ !compiler. is_like_clang_cl( ) ,
876
+ "Should not use clang-cl by default"
877
+ ) ;
878
+ }
880
879
881
- let test = Test :: msvc_autodetect ( ) ;
880
+ #[ test]
881
+ fn msvc_prefer_clang_cl_over_msvc_enabled ( ) {
882
+ reset_env ( ) ;
882
883
883
- let compiler = test
884
- . gcc ( )
885
- // When prefer_clang_cl_over_msvc is true, should use clang-cl.exe
886
- . prefer_clang_cl_over_msvc ( true )
887
- . try_get_compiler ( )
888
- . expect ( "Failed to get compiler" ) ;
889
-
890
- assert ! (
891
- compiler. is_like_clang_cl( ) ,
892
- "clang-cl.exe should be identified as clang-cl-like, got {:?}" ,
893
- compiler
894
- ) ;
895
- assert ! (
896
- compiler. is_like_msvc( ) ,
897
- "clang-cl should still be MSVC-like"
898
- ) ;
899
- }
884
+ let test = Test :: msvc_autodetect ( ) ;
900
885
901
- #[ test]
902
- #[ cfg( windows) ]
903
- fn msvc_prefer_clang_cl_over_msvc_respects_explicit_cc_env ( ) {
904
- reset_env ( ) ;
886
+ let compiler = test
887
+ . gcc ( )
888
+ // When prefer_clang_cl_over_msvc is true, should use clang-cl.exe
889
+ . prefer_clang_cl_over_msvc ( true )
890
+ . try_get_compiler ( )
891
+ . expect ( "Failed to get compiler" ) ;
892
+
893
+ assert ! (
894
+ compiler. is_like_clang_cl( ) ,
895
+ "clang-cl.exe should be identified as clang-cl-like, got {:?}" ,
896
+ compiler
897
+ ) ;
898
+ assert ! (
899
+ compiler. is_like_msvc( ) ,
900
+ "clang-cl should still be MSVC-like"
901
+ ) ;
902
+ }
905
903
906
- let test = Test :: msvc_autodetect ( ) ;
907
- let compiler = test
908
- . gcc ( )
909
- // We can't set the CC=cl.exe environment variable directly in the test as it's removed
910
- // in mod.rs, so we simulate it by setting the compiler directly
911
- . compiler ( "cl.exe" )
912
- . prefer_clang_cl_over_msvc ( true )
913
- . try_get_compiler ( )
914
- . expect ( "Failed to get compiler" ) ;
915
-
916
- // The preference should not override explicit compiler setting
917
- assert ! ( compiler. is_like_msvc( ) , "Should still be MSVC-like" ) ;
918
- assert ! (
919
- !compiler. is_like_clang_cl( ) ,
920
- "Should NOT use clang-cl when CC is explicitly set to cl.exe, got {:?}" ,
921
- compiler
922
- ) ;
923
- }
904
+ #[ test]
905
+ fn msvc_prefer_clang_cl_over_msvc_respects_explicit_cc_env ( ) {
906
+ reset_env ( ) ;
924
907
925
- #[ test]
926
- #[ cfg( windows) ]
927
- fn msvc_prefer_clang_cl_over_msvc_cpp_mode ( ) {
928
- reset_env ( ) ;
908
+ let test = Test :: msvc_autodetect ( ) ;
929
909
930
- let test = Test :: msvc_autodetect ( ) ;
931
- let compiler = test
932
- . gcc ( )
933
- . cpp ( true )
934
- . prefer_clang_cl_over_msvc ( true )
935
- . try_get_compiler ( )
936
- . expect ( "Failed to get compiler" ) ;
937
-
938
- // Verify clang-cl.exe works correctly in C++ mode
939
- assert ! (
940
- compiler. is_like_clang_cl( ) ,
941
- "clang-cl.exe should be identified as clang-cl-like in C++ mode"
942
- ) ;
943
- assert ! (
944
- compiler. is_like_msvc( ) ,
945
- "clang-cl should still be MSVC-like in C++ mode"
946
- ) ;
910
+ //std::env::set_var("CC", "cl.exe");
911
+ let compiler = test
912
+ . gcc ( )
913
+ . __set_env ( "CC" , "cl.exe" )
914
+ . prefer_clang_cl_over_msvc ( true )
915
+ . try_get_compiler ( )
916
+ . expect ( "Failed to get compiler" ) ;
917
+
918
+ // The preference should not override explicit compiler setting
919
+ assert ! ( compiler. is_like_msvc( ) , "Should still be MSVC-like" ) ;
920
+ assert ! (
921
+ !compiler. is_like_clang_cl( ) ,
922
+ "Should NOT use clang-cl when CC is explicitly set to cl.exe, got {:?}" ,
923
+ compiler
924
+ ) ;
925
+ std:: env:: remove_var ( "CC" ) ; // Clean up after test
926
+ }
927
+
928
+ #[ test]
929
+ fn msvc_prefer_clang_cl_over_msvc_cpp_mode ( ) {
930
+ reset_env ( ) ;
931
+
932
+ let test = Test :: msvc_autodetect ( ) ;
933
+ let compiler = test
934
+ . gcc ( )
935
+ . cpp ( true )
936
+ . prefer_clang_cl_over_msvc ( true )
937
+ . try_get_compiler ( )
938
+ . expect ( "Failed to get compiler" ) ;
939
+
940
+ // Verify clang-cl.exe works correctly in C++ mode
941
+ assert ! (
942
+ compiler. is_like_clang_cl( ) ,
943
+ "clang-cl.exe should be identified as clang-cl-like in C++ mode"
944
+ ) ;
945
+ assert ! (
946
+ compiler. is_like_msvc( ) ,
947
+ "clang-cl should still be MSVC-like in C++ mode"
948
+ ) ;
949
+ }
947
950
}
0 commit comments