Commit 392a0b3
Changed files (2)
tests/fixture_tests.rs
@@ -1,71 +0,0 @@
-use assert_cmd::Command;
-use std::fs;
-use std::path::{Path, PathBuf};
-
-fn discover_fixtures() -> Vec<PathBuf> {
- let fixtures_dir = Path::new("tests/fixtures");
- let mut fixtures = Vec::new();
-
- if let Ok(entries) = fs::read_dir(fixtures_dir) {
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- let input_file = path.join("input.sql");
- let output_file = path.join("output.sql");
-
- if input_file.exists() && output_file.exists() {
- fixtures.push(path);
- }
- }
- }
- }
-
- fixtures.sort();
- fixtures
-}
-
-fn run_fixture_test(fixture_path: &Path) {
- let scenario_name = fixture_path.file_name().unwrap().to_str().unwrap();
-
- let input_file = fixture_path.join("input.sql");
- let output_file = fixture_path.join("output.sql");
-
- let input_sql = fs::read_to_string(&input_file)
- .unwrap_or_else(|_| panic!("Failed to read input file: {}", input_file.display()));
-
- let expected_output = fs::read_to_string(&output_file)
- .unwrap_or_else(|_| panic!("Failed to read output file: {}", output_file.display()));
-
- let mut cmd = Command::cargo_bin("xlg-sqlfmt").unwrap();
-
- // Handle the special case of invalid SQL (should fail and output original SQL)
- if scenario_name == "invalid_sql" {
- cmd.write_stdin(input_sql.as_str())
- .assert()
- .failure()
- .stdout(format!("{}\n", expected_output));
- } else {
- cmd.write_stdin(input_sql.as_str())
- .assert()
- .success()
- .stdout(format!("{}\n", expected_output));
- }
-}
-
-#[test]
-fn test_all_fixtures() {
- let fixtures = discover_fixtures();
-
- assert!(
- !fixtures.is_empty(),
- "No fixtures found in tests/fixtures directory"
- );
-
- for fixture_path in fixtures {
- let scenario_name = fixture_path.file_name().unwrap().to_str().unwrap();
-
- println!("Running fixture test: {}", scenario_name);
-
- run_fixture_test(&fixture_path);
- }
-}
tests/integration.rs
@@ -1,4 +1,6 @@
use assert_cmd::Command;
+use std::fs;
+use std::path::{Path, PathBuf};
#[test]
fn test_cli_basic_select() {
@@ -225,3 +227,70 @@ fn test_cli_your_original_example() {
.success()
.stdout("SELECT 1 AS one\nFROM\n \"admin_roles\"\nWHERE admin_roles.name = 'root'\n AND admin_roles.organization_id = 1\nLIMIT 1;\n");
}
+
+fn discover_fixtures() -> Vec<PathBuf> {
+ let fixtures_dir = Path::new("tests/fixtures");
+ let mut fixtures = Vec::new();
+
+ if let Ok(entries) = fs::read_dir(fixtures_dir) {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if path.is_dir() {
+ let input_file = path.join("input.sql");
+ let output_file = path.join("output.sql");
+
+ if input_file.exists() && output_file.exists() {
+ fixtures.push(path);
+ }
+ }
+ }
+ }
+
+ fixtures.sort();
+ fixtures
+}
+
+fn run_fixture_test(fixture_path: &Path) {
+ let scenario_name = fixture_path.file_name().unwrap().to_str().unwrap();
+
+ let input_file = fixture_path.join("input.sql");
+ let output_file = fixture_path.join("output.sql");
+
+ let input_sql = fs::read_to_string(&input_file)
+ .unwrap_or_else(|_| panic!("Failed to read input file: {}", input_file.display()));
+
+ let expected_output = fs::read_to_string(&output_file)
+ .unwrap_or_else(|_| panic!("Failed to read output file: {}", output_file.display()));
+
+ let mut cmd = Command::cargo_bin("xlg-sqlfmt").unwrap();
+
+ if scenario_name == "invalid_sql" {
+ cmd.write_stdin(input_sql.as_str())
+ .assert()
+ .failure()
+ .stdout(format!("{}\n", expected_output));
+ } else {
+ cmd.write_stdin(input_sql.as_str())
+ .assert()
+ .success()
+ .stdout(format!("{}\n", expected_output));
+ }
+}
+
+#[test]
+fn test_all_fixtures() {
+ let fixtures = discover_fixtures();
+
+ assert!(
+ !fixtures.is_empty(),
+ "No fixtures found in tests/fixtures directory"
+ );
+
+ for fixture_path in fixtures {
+ let scenario_name = fixture_path.file_name().unwrap().to_str().unwrap();
+
+ println!("Running fixture test: {}", scenario_name);
+
+ run_fixture_test(&fixture_path);
+ }
+}