// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗ // ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝ // ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗ // ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║ // ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝ // ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ #[cfg(test)] mod passing { use assert_cmd::prelude::*; use std::env; use std::fs; use std::path::Path; use std::process::Command; use url::Url; #[test] fn local_file_target_input_relative_target_path() -> Result<(), Box> { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; let cwd_normalized: String = str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/"); let out = cmd .arg("-M") .arg(if cfg!(windows) { "src\\tests\\data\\basic\\local-file.html" } else { "src/tests/data/basic/local-file.html" }) .output() .unwrap(); let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" }; // STDOUT should contain HTML from the local file assert_eq!( std::str::from_utf8(&out.stdout).unwrap(), "\ \n \ \n \ Local HTML file\n \ \n \ \n\n\n\n \ \"\"\n \ Tricky href\n \ Remote URL\n \ \n\n\n\n\ \n\ " ); // STDERR should contain list of retrieved file URLs, two missing assert_eq!( std::str::from_utf8(&out.stderr).unwrap(), format!( "\ {file}{cwd}/src/tests/data/basic/local-file.html\n \ {file}{cwd}/src/tests/data/basic/local-style.css\n \ {file}{cwd}/src/tests/data/basic/local-style-does-not-exist.css (not found)\n \ {file}{cwd}/src/tests/data/basic/monolith.png (not found)\n \ {file}{cwd}/src/tests/data/basic/local-script.js\n\ ", file = file_url_protocol, cwd = cwd_normalized ) ); // The exit code should be 0 out.assert().code(0); Ok(()) } #[test] fn local_file_target_input_absolute_target_path() -> Result<(), Box> { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; let path_html: &Path = Path::new("src/tests/data/basic/local-file.html"); let out = cmd .arg("-M") .arg("-Ijci") .arg(path_html.as_os_str()) .output() .unwrap(); // STDOUT should contain HTML from the local file assert_eq!( std::str::from_utf8(&out.stdout).unwrap(), format!( "\ \ \n \ \n \ Local HTML file\n \ \n \ \n\n\n\n \ \"\"\n \ Tricky href\n \ Remote URL\n \ \n\n\n\n\ \n\ ", empty_image = empty_image!() ) ); // STDERR should contain only the target file assert_eq!( std::str::from_utf8(&out.stderr).unwrap(), format!( "{file_url_html}\n", file_url_html = Url::from_file_path(fs::canonicalize(&path_html).unwrap()) .unwrap() .into_string(), ) ); // The exit code should be 0 out.assert().code(0); Ok(()) } #[test] fn local_file_url_target_input() -> Result<(), Box> { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; let cwd_normalized: String = str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/"); let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" }; let out = cmd .arg("-M") .arg("-cji") .arg(if cfg!(windows) { format!( "{file}{cwd}/src/tests/data/basic/local-file.html", file = file_url_protocol, cwd = cwd_normalized, ) } else { format!( "{file}{cwd}/src/tests/data/basic/local-file.html", file = file_url_protocol, cwd = cwd_normalized, ) }) .output() .unwrap(); // STDOUT should contain HTML from the local file assert_eq!( std::str::from_utf8(&out.stdout).unwrap(), format!( "\ \ \n \ \n \ Local HTML file\n \ \n \ \n\n\n\n \ \"\"\n \ Tricky href\n \ Remote URL\n \ \n\n\n\n\ \n\ ", empty_image = empty_image!() ) ); // STDERR should contain list of retrieved file URLs assert_eq!( std::str::from_utf8(&out.stderr).unwrap(), format!( "{file}{cwd}/src/tests/data/basic/local-file.html\n", file = file_url_protocol, cwd = cwd_normalized, ) ); // The exit code should be 0 out.assert().code(0); Ok(()) } #[test] fn embed_file_url_local_asset_within_style_attribute() -> Result<(), Box> { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; let path_html: &Path = Path::new("src/tests/data/svg/index.html"); let path_svg: &Path = Path::new("src/tests/data/svg/image.svg"); let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap(); // STDOUT should contain HTML with date URL for background-image in it assert_eq!( std::str::from_utf8(&out.stdout).unwrap(), "