@@ -598,3 +598,50 @@ fn get_lib_dir_from_rustc(rustc: &Path) -> anyhow::Result<PathBuf> {
598
598
599
599
Ok ( Path :: new ( sysroot_path. as_ref ( ) . trim ( ) ) . join ( "lib" ) )
600
600
}
601
+
602
+ #[ cfg( test) ]
603
+ mod tests {
604
+ use super :: * ;
605
+
606
+ #[ test]
607
+ fn fill_libraries ( ) {
608
+ let mut components = ToolchainComponents :: default ( ) ;
609
+
610
+ // create mock dir and libraries
611
+ let temp_dir: tempfile:: TempDir = tempfile:: tempdir ( ) . unwrap ( ) ;
612
+ let lib_rustc_path = create_temp_lib_path ( "librustc_driver.so" , & temp_dir) ;
613
+ let lib_std_path = create_temp_lib_path ( "libstd.so" , & temp_dir) ;
614
+ let lib_test_path = create_temp_lib_path ( "libtest.so" , & temp_dir) ;
615
+ let lib_new_llvm_path =
616
+ create_temp_lib_path ( "libLLVM.so.18.1-rust-1.78.0-nightly" , & temp_dir) ;
617
+
618
+ components. fill_libraries ( temp_dir. path ( ) ) . unwrap ( ) ;
619
+
620
+ assert_eq ! ( components. lib_rustc, Some ( lib_rustc_path) ) ;
621
+ assert_eq ! ( components. lib_std, Some ( lib_std_path) ) ;
622
+ assert_eq ! ( components. lib_test, Some ( lib_test_path) ) ;
623
+ assert_eq ! ( components. lib_llvm, Some ( lib_new_llvm_path) ) ;
624
+ }
625
+
626
+ #[ test]
627
+ fn fill_old_llvm_library ( ) {
628
+ let mut components = ToolchainComponents :: default ( ) ;
629
+ let lib_old_llvm = "libLLVM-17-rust-1.76.0-stable.so" ;
630
+
631
+ // create mock dir and libraries
632
+ let temp_dir: tempfile:: TempDir = tempfile:: tempdir ( ) . unwrap ( ) ;
633
+ let lib_old_llvm_path = create_temp_lib_path ( lib_old_llvm, & temp_dir) ;
634
+
635
+ components. fill_libraries ( temp_dir. path ( ) ) . unwrap ( ) ;
636
+
637
+ assert_eq ! ( components. lib_llvm, Some ( lib_old_llvm_path) ) ;
638
+ }
639
+
640
+ fn create_temp_lib_path ( lib_name : & str , temp_dir : & tempfile:: TempDir ) -> PathBuf {
641
+ let lib_path = temp_dir. path ( ) . join ( lib_name) ;
642
+ // create mock file
643
+ File :: create ( & lib_path) . unwrap ( ) ;
644
+
645
+ lib_path
646
+ }
647
+ }
0 commit comments