main
1use assert_cmd::Command;
2use std::fs;
3use std::path::{Path, PathBuf};
4
5fn discover_fixtures() -> Vec<PathBuf> {
6 let fixtures_dir = Path::new("tests/fixtures");
7 let mut fixtures = Vec::new();
8
9 if let Ok(entries) = fs::read_dir(fixtures_dir) {
10 for entry in entries.flatten() {
11 let path = entry.path();
12 if path.is_dir() {
13 let input_file = path.join("input.sql");
14 let output_file = path.join("output.sql");
15
16 if input_file.exists() && output_file.exists() {
17 fixtures.push(path);
18 }
19 }
20 }
21 }
22
23 fixtures.sort();
24 fixtures
25}
26
27#[test]
28fn test_all_fixtures() {
29 for fixture_path in discover_fixtures() {
30 let input_file = fixture_path.join("input.sql");
31 let output_file = fixture_path.join("output.sql");
32 let input_sql = fs::read_to_string(&input_file).expect("");
33 let expected_output = fs::read_to_string(&output_file).expect("");
34
35 let mut cmd = Command::cargo_bin("xlg-sqlfmt").unwrap();
36 let expected_with_newline = if expected_output.is_empty() {
37 expected_output.to_string()
38 } else {
39 format!("{}\n", expected_output)
40 };
41 cmd.write_stdin(input_sql.as_str())
42 .assert()
43 .success()
44 .stdout(expected_with_newline);
45 }
46}