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!("{}_html", dir_name));
25 let gemini_dir = parent.join(format!("{}_gemini", dir_name));
27 let _cleanup = TestDir {
28 paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()]
31 // Create test input files
32 create_test_file(&test_dir.join("_layout.html"), "\
34 <head><title>{{ title }}</title></head>
35 <body>{{ content }}</body>
38 create_test_file(&test_dir.join("test.gmi"), "\
39 --- title: Page Is Cool!
43 create_test_file(&test_dir.join("test.png"), "A picture of a cute cat");
45 // Run the program from the test directory
46 let status = Command::new(env!("CARGO_BIN_EXE_page"))
47 .current_dir(&test_dir)
49 .expect("Failed to execute command");
51 assert!(status.success());
53 assert!(html_dir.exists());
54 assert!(gemini_dir.exists());
56 let html_output = html_dir.join("test.html");
57 assert_file_contents(&html_output, "\
59 <head><title>Page Is Cool!</title></head>
60 <body><section class=\"h1\">
68 let html_asset_output = html_dir.join("test.png");
69 assert_file_contents(&html_asset_output, "A picture of a cute cat");
71 let gemini_output = gemini_dir.join("test.gmi");
72 assert_file_contents(&gemini_output, "\
77 let gemini_asset_output = gemini_dir.join("test.png");
78 assert!(gemini_asset_output.exists());
79 let gemini_asset_content = read_to_string(gemini_asset_output).unwrap();
80 assert_eq!(gemini_asset_content, "A picture of a cute cat");
84 fn test_missing_layout() {
85 let test_dir = setup_test_dir();
86 let dir_name = test_dir.file_name().unwrap().to_string_lossy();
87 let parent = test_dir.parent().unwrap();
88 let html_dir = parent.join(format!("{}_html", dir_name));
89 let gemini_dir = parent.join(format!("{}_gemini", dir_name));
91 let _cleanup = TestDir {
92 paths: vec![test_dir.clone(), html_dir.clone(), gemini_dir.clone()]
95 // Create test input files
96 create_test_file(&test_dir.join("test.gmi"), "\
97 --- title: Page Is Cool!
101 create_test_file(&test_dir.join("test.png"), "A picture of a cute cat");
103 // Run the program from the test directory
104 let status = Command::new(env!("CARGO_BIN_EXE_page"))
105 .current_dir(&test_dir)
107 .expect("Failed to execute command");
109 assert!(!status.success());
111 assert!(!html_dir.exists());
112 assert!(!gemini_dir.exists());