docs(test): Document main_file function

This commit is contained in:
Ed Page 2024-07-18 14:33:12 -05:00
parent 170756601c
commit c9dddd27c8

View File

@ -540,10 +540,24 @@ pub fn project_in_home(name: &str) -> ProjectBuilder {
// === Helpers ===
pub fn main_file(println: &str, deps: &[&str]) -> String {
/// Generate a `main.rs` printing the specified text
///
/// ```rust
/// # use cargo_test_support::main_file;
/// # mod dep {
/// # fn bar() -> &'static str {
/// # "world"
/// # }
/// # }
/// main_file(
/// r#""hello {}", dep::bar()"#,
/// &[]
/// );
/// ```
pub fn main_file(println: &str, externed_deps: &[&str]) -> String {
let mut buf = String::new();
for dep in deps.iter() {
for dep in externed_deps.iter() {
buf.push_str(&format!("extern crate {};\n", dep));
}