@@ -774,6 +774,24 @@ impl Step for RustdocJSNotStd {
774774 }
775775}
776776
777+ fn check_if_browser_ui_test_is_installed_global ( npm : & Path , global : bool ) -> bool {
778+ let mut command = Command :: new ( & npm) ;
779+ command. arg ( "list" ) . arg ( "--depth=0" ) ;
780+ if global {
781+ command. arg ( "--global" ) ;
782+ }
783+ let lines = command
784+ . output ( )
785+ . map ( |output| String :: from_utf8_lossy ( & output. stdout ) . into_owned ( ) )
786+ . unwrap_or ( String :: new ( ) ) ;
787+ lines. contains ( & " browser-ui-test@" )
788+ }
789+
790+ fn check_if_browser_ui_test_is_installed ( npm : & Path ) -> bool {
791+ check_if_browser_ui_test_is_installed_global ( npm, false )
792+ || check_if_browser_ui_test_is_installed_global ( npm, true )
793+ }
794+
777795#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
778796pub struct RustdocGUI {
779797 pub target : TargetSelection ,
@@ -786,7 +804,17 @@ impl Step for RustdocGUI {
786804 const ONLY_HOSTS : bool = true ;
787805
788806 fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
789- run. path ( "src/test/rustdoc-gui" )
807+ let builder = run. builder ;
808+ let run = run. path ( "src/test/rustdoc-gui" ) ;
809+ run. default_condition (
810+ builder. config . nodejs . is_some ( )
811+ && builder
812+ . config
813+ . npm
814+ . as_ref ( )
815+ . map ( |p| check_if_browser_ui_test_is_installed ( p) )
816+ . unwrap_or ( false ) ,
817+ )
790818 }
791819
792820 fn make_run ( run : RunConfig < ' _ > ) {
@@ -795,58 +823,54 @@ impl Step for RustdocGUI {
795823 }
796824
797825 fn run ( self , builder : & Builder < ' _ > ) {
798- if let ( Some ( nodejs) , Some ( npm) ) = ( & builder. config . nodejs , & builder. config . npm ) {
799- builder. ensure ( compile:: Std { compiler : self . compiler , target : self . target } ) ;
800-
801- // The goal here is to check if the necessary packages are installed, and if not, we
802- // display a warning and move on.
803- let mut command = Command :: new ( & npm) ;
804- command. arg ( "list" ) . arg ( "--depth=0" ) ;
805- let lines = command
806- . output ( )
807- . map ( |output| String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
808- . unwrap_or ( String :: new ( ) ) ;
809- if !lines. contains ( & " browser-ui-test@" ) {
810- println ! (
811- "warning: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
812- dependency is missing",
813- ) ;
814- println ! (
815- "If you want to install the `{0}` dependency, run `npm install {0}`" ,
816- "browser-ui-test" ,
817- ) ;
818- return ;
819- }
826+ let nodejs = builder. config . nodejs . as_ref ( ) . expect ( "nodejs isn't available" ) ;
827+ let npm = builder. config . npm . as_ref ( ) . expect ( "npm isn't available" ) ;
820828
821- let out_dir = builder . test_out ( self . target ) . join ( "rustdoc-gui" ) ;
829+ builder . ensure ( compile :: Std { compiler : self . compiler , target : self . target } ) ;
822830
823- // We remove existing folder to be sure there won't be artifacts remaining.
824- let _ = fs:: remove_dir_all ( & out_dir) ;
831+ // The goal here is to check if the necessary packages are installed, and if not, we
832+ // panic.
833+ if !check_if_browser_ui_test_is_installed ( & npm) {
834+ eprintln ! (
835+ "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
836+ dependency is missing",
837+ ) ;
838+ eprintln ! (
839+ "If you want to install the `{0}` dependency, run `npm install {0}`" ,
840+ "browser-ui-test" ,
841+ ) ;
842+ panic ! ( "Cannot run rustdoc-gui tests" ) ;
843+ }
825844
826- // We generate docs for the libraries present in the rustdoc-gui's src folder.
827- let libs_dir = builder. build . src . join ( "src/test/rustdoc-gui/src" ) ;
828- for entry in libs_dir. read_dir ( ) . expect ( "read_dir call failed" ) {
829- let entry = entry. expect ( "invalid entry" ) ;
830- let path = entry. path ( ) ;
831- if path. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
832- let mut command = builder. rustdoc_cmd ( self . compiler ) ;
833- command. arg ( path) . arg ( "-o" ) . arg ( & out_dir) ;
834- builder. run ( & mut command) ;
835- }
836- }
845+ let out_dir = builder. test_out ( self . target ) . join ( "rustdoc-gui" ) ;
837846
838- // We now run GUI tests.
839- let mut command = Command :: new ( & nodejs) ;
840- command
841- . arg ( builder. build . src . join ( "src/tools/rustdoc-gui/tester.js" ) )
842- . arg ( "--doc-folder" )
843- . arg ( out_dir)
844- . arg ( "--tests-folder" )
845- . arg ( builder. build . src . join ( "src/test/rustdoc-gui" ) ) ;
846- builder. run ( & mut command) ;
847- } else {
848- builder. info ( "No nodejs found, skipping \" src/test/rustdoc-gui\" tests" ) ;
847+ // We remove existing folder to be sure there won't be artifacts remaining.
848+ let _ = fs:: remove_dir_all ( & out_dir) ;
849+
850+ let mut nb_generated = 0 ;
851+ // We generate docs for the libraries present in the rustdoc-gui's src folder.
852+ let libs_dir = builder. build . src . join ( "src/test/rustdoc-gui/src" ) ;
853+ for entry in libs_dir. read_dir ( ) . expect ( "read_dir call failed" ) {
854+ let entry = entry. expect ( "invalid entry" ) ;
855+ let path = entry. path ( ) ;
856+ if path. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
857+ let mut command = builder. rustdoc_cmd ( self . compiler ) ;
858+ command. arg ( path) . arg ( "-o" ) . arg ( & out_dir) ;
859+ builder. run ( & mut command) ;
860+ nb_generated += 1 ;
861+ }
849862 }
863+ assert ! ( nb_generated > 0 , "no documentation was generated..." ) ;
864+
865+ // We now run GUI tests.
866+ let mut command = Command :: new ( & nodejs) ;
867+ command
868+ . arg ( builder. build . src . join ( "src/tools/rustdoc-gui/tester.js" ) )
869+ . arg ( "--doc-folder" )
870+ . arg ( out_dir)
871+ . arg ( "--tests-folder" )
872+ . arg ( builder. build . src . join ( "src/test/rustdoc-gui" ) ) ;
873+ builder. run ( & mut command) ;
850874 }
851875}
852876
0 commit comments