diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-03 23:17:06 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-03 23:17:06 +0100 |
| commit | 1c5797fadeea6be505c01f13508203ba234cbdfa (patch) | |
| tree | dd18df7a04b6c3496a2066573575b1760e550590 /tests | |
| parent | 260e8ec69b8e08b9fd105bf688e7a3a9fafecd61 (diff) | |
Update main and file_finder tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cli_test.rs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/cli_test.rs b/tests/cli_test.rs new file mode 100644 index 0000000..0bb46bb --- /dev/null +++ b/tests/cli_test.rs @@ -0,0 +1,113 @@ +use std::env; +use std::fs::read_to_string; +use std::path::PathBuf; +use std::process::Command; +use test_utilities::*; + +struct TestDir { + paths: Vec<PathBuf>, +} + +impl Drop for TestDir { + fn drop(&mut self) { + for path in &self.paths { + cleanup_test_dir(path); + } + } +} + +#[test] +fn test_basic_generation() { + let test_dir = setup_test_dir(); + let dir_name = test_dir.file_name().unwrap().to_string_lossy(); + let parent = test_dir.parent().unwrap(); + let html_dir = parent.join(format!("{}_html", dir_name)); + let gemini_dir = parent.join(format!("{}_gemini", dir_name)); + + let _cleanup = TestDir { + paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()] + }; + + // Create test input files + create_test_file(&test_dir.join("_layout.html"), "\ +<html> +<head><title>{{ title }}</title></head> +<body>{{ content }}</body> +</html> +"); + create_test_file(&test_dir.join("test.gmi"), "\ +--- title: Page Is Cool! +# Test +Hello world +"); + create_test_file(&test_dir.join("test.png"), "A picture of a cute cat"); + + // Run the program from the test directory + let status = Command::new(env!("CARGO_BIN_EXE_page")) + .current_dir(&test_dir) + .status() + .expect("Failed to execute command"); + + assert!(status.success()); + + assert!(html_dir.exists()); + assert!(gemini_dir.exists()); + + let html_output = html_dir.join("test.html"); + assert_file_contents(&html_output, "\ +<html> +<head><title>Page Is Cool!</title></head> +<body><section class=\"h1\"> +<h1> Test</h1> +<p>Hello world</p> +</section> +</body> +</html> +"); + + let html_asset_output = html_dir.join("test.png"); + assert_file_contents(&html_asset_output, "A picture of a cute cat"); + + let gemini_output = gemini_dir.join("test.gmi"); + assert_file_contents(&gemini_output, "\ +# Test +Hello world +"); + + let gemini_asset_output = gemini_dir.join("test.png"); + assert!(gemini_asset_output.exists()); + let gemini_asset_content = read_to_string(gemini_asset_output).unwrap(); + assert_eq!(gemini_asset_content, "A picture of a cute cat"); +} + +#[test] +fn test_missing_layout() { + let test_dir = setup_test_dir(); + let dir_name = test_dir.file_name().unwrap().to_string_lossy(); + let parent = test_dir.parent().unwrap(); + let html_dir = parent.join(format!("{}_html", dir_name)); + let gemini_dir = parent.join(format!("{}_gemini", dir_name)); + + let _cleanup = TestDir { + paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()] + }; + + // Create test input files + create_test_file(&test_dir.join("test.gmi"), "\ +--- title: Page Is Cool! +# Test +Hello world +"); + create_test_file(&test_dir.join("test.png"), "A picture of a cute cat"); + + // Run the program from the test directory + let status = Command::new(env!("CARGO_BIN_EXE_page")) + .current_dir(&test_dir) + .status() + .expect("Failed to execute command"); + + assert!(!status.success()); + + assert!(!html_dir.exists()); + assert!(!gemini_dir.exists()); +} |