2 use std::fs::read_to_string;
3 use std::path::PathBuf;
4 use std::process::Command;
11 impl Drop for TestDir {
13 for path in &self.paths {
14 cleanup_test_dir(path);
20 fn test_basic_generation() {
21 let test_dir = setup_test_dir();
22 let dir_name = test_dir.file_name().unwrap().to_string_lossy();
23 let parent = test_dir.parent().unwrap();
24 let html_dir = parent.join(format!("{dir_name}_html"));
25 let gemini_dir = parent.join(format!("{dir_name}_gemini"));
27 let _cleanup = TestDir {
28 paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()],
31 // Create test input files
33 &test_dir.join("_layout.html"),
36 <head><title>{{ title }}</title></head>
37 <body>{{ content }}</body>
42 &test_dir.join("test.gmi"),
44 --- title: Page Is Cool!
49 create_test_file(&test_dir.join("test.png"), "A picture of a cute cat");
51 // Run the program from the test directory
52 let status = Command::new(env!("CARGO_BIN_EXE_page"))
53 .current_dir(&test_dir)
55 .expect("Failed to execute command");
57 assert!(status.success());
59 assert!(html_dir.exists());
60 assert!(gemini_dir.exists());
62 let html_output = html_dir.join("test.html");
67 <head><title>Page Is Cool!</title></head>
68 <body><section class=\"h1\">
77 let html_asset_output = html_dir.join("test.png");
78 assert_file_contents(&html_asset_output, "A picture of a cute cat");
80 let gemini_output = gemini_dir.join("test.gmi");
89 let gemini_asset_output = gemini_dir.join("test.png");
90 assert!(gemini_asset_output.exists());
91 let gemini_asset_content = read_to_string(gemini_asset_output).unwrap();
92 assert_eq!(gemini_asset_content, "A picture of a cute cat");
96 fn test_missing_layout() {
97 let test_dir = setup_test_dir();
98 let dir_name = test_dir.file_name().unwrap().to_string_lossy();
99 let parent = test_dir.parent().unwrap();
100 let html_dir = parent.join(format!("{dir_name}_html"));
101 let gemini_dir = parent.join(format!("{dir_name}_gemini"));
103 let _cleanup = TestDir {
104 paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()],
107 // Create test input files
109 &test_dir.join("test.gmi"),
111 --- title: Page Is Cool!
116 create_test_file(&test_dir.join("test.png"), "A picture of a cute cat");
118 // Run the program from the test directory
119 let status = Command::new(env!("CARGO_BIN_EXE_page"))
120 .current_dir(&test_dir)
122 .expect("Failed to execute command");
124 assert!(!status.success());
126 assert!(!html_dir.exists());
127 assert!(!gemini_dir.exists());