11use cargo:: core:: compiler:: Lto ;
22use cargo_test_support:: registry:: Package ;
3- use cargo_test_support:: { project, Project } ;
3+ use cargo_test_support:: { basic_manifest , project, Project } ;
44use std:: process:: Output ;
55
66#[ cargo_test]
@@ -514,16 +514,19 @@ fn cdylib_and_rlib() {
514514 p. cargo ( "test --release -v --manifest-path bar/Cargo.toml" )
515515 . with_stderr_unordered (
516516 "\
517- [FRESH] registry v0.0.1
518- [FRESH] registry-shared v0.0.1
517+ [COMPILING] registry v0.0.1
518+ [COMPILING] registry-shared v0.0.1
519+ [RUNNING] `rustc --crate-name registry [..]-C embed-bitcode=no[..]
520+ [RUNNING] `rustc --crate-name registry_shared [..]-C embed-bitcode=no[..]
519521[COMPILING] bar [..]
522+ [RUNNING] `rustc --crate-name bar [..]--crate-type cdylib --crate-type rlib [..]-C embed-bitcode=no[..]
520523[RUNNING] `rustc --crate-name bar [..]-C embed-bitcode=no --test[..]
521524[RUNNING] `rustc --crate-name b [..]-C embed-bitcode=no --test[..]
522525[FINISHED] [..]
523- [RUNNING] [..]
524- [RUNNING] [..]
526+ [RUNNING] [..]target/release/deps/bar-[..]
527+ [RUNNING] [..]target/release/deps/b-[..]
525528[DOCTEST] bar
526- [RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --test [..]
529+ [RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --test [..]-C embed-bitcode=no[..]
527530" ,
528531 )
529532 . run ( ) ;
@@ -627,7 +630,7 @@ fn test_profile() {
627630[COMPILING] bar v0.0.1
628631[RUNNING] `rustc --crate-name bar [..]crate-type lib[..]
629632[COMPILING] foo [..]
630- [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no [..]
633+ [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C linker-plugin-lto [..]
631634[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C lto=thin [..]--test[..]
632635[FINISHED] [..]
633636[RUNNING] [..]
@@ -680,7 +683,7 @@ fn dev_profile() {
680683[COMPILING] bar v0.0.1
681684[RUNNING] `rustc --crate-name bar [..]crate-type lib[..]
682685[COMPILING] foo [..]
683- [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C linker-plugin-lto [..]
686+ [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no [..]
684687[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C embed-bitcode=no [..]--test[..]
685688[FINISHED] [..]
686689[RUNNING] [..]
@@ -689,3 +692,57 @@ fn dev_profile() {
689692" )
690693 . run ( ) ;
691694}
695+
696+ #[ cargo_test]
697+ fn doctest ( ) {
698+ let p = project ( )
699+ . file (
700+ "Cargo.toml" ,
701+ r#"
702+ [package]
703+ name = "foo"
704+ version = "0.1.0"
705+ edition = "2018"
706+
707+ [profile.release]
708+ lto = true
709+
710+ [dependencies]
711+ bar = { path = "bar" }
712+ "# ,
713+ )
714+ . file (
715+ "src/lib.rs" ,
716+ r#"
717+ /// Foo!
718+ ///
719+ /// ```
720+ /// foo::foo();
721+ /// ```
722+ pub fn foo() { bar::bar(); }
723+ "# ,
724+ )
725+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
726+ . file (
727+ "bar/src/lib.rs" ,
728+ r#"
729+ pub fn bar() { println!("hi!"); }
730+ "# ,
731+ )
732+ . build ( ) ;
733+
734+ p. cargo ( "test --doc --release -v" )
735+ . with_stderr_contains ( "[..]`rustc --crate-name bar[..]-C embed-bitcode=no[..]" )
736+ . with_stderr_contains ( "[..]`rustc --crate-name foo[..]-C embed-bitcode=no[..]" )
737+ // embed-bitcode should be harmless here
738+ . with_stderr_contains ( "[..]`rustdoc [..]-C embed-bitcode=no[..]" )
739+ . run ( ) ;
740+
741+ // Try with bench profile.
742+ p. cargo ( "test --doc --release -v" )
743+ . env ( "CARGO_PROFILE_BENCH_LTO" , "true" )
744+ . with_stderr_contains ( "[..]`rustc --crate-name bar[..]-C linker-plugin-lto[..]" )
745+ . with_stderr_contains ( "[..]`rustc --crate-name foo[..]-C linker-plugin-lto[..]" )
746+ . with_stderr_contains ( "[..]`rustdoc [..]-C lto[..]" )
747+ . run ( ) ;
748+ }
0 commit comments