diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a706cff1..1e45d6a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,7 @@ If you have [Nix](https://nixos.org/download/) with flakes enabled, `nix develop | `nix flake check` | formatting, plus the flake's own version assertions | | `nix run .#lint-rust` | `cargo fmt --check` and `cargo clippy` | | `nix run .#test-rust` | the Rust test suites | +| `nix run .#test-sql -- ` | run a single [SQL test file](./tests/sql_test_files/README.md) | | `nix run .#test-browser` | the Playwright suites | | `nix run .#test-examples` | one example's Hurl suite | | `nix build .#odbc-drivers` | an `odbcinst.ini`; point `ODBCSYSINI` at it for the ODBC tests | diff --git a/flake.nix b/flake.nix index 538f3e67..6524a692 100644 --- a/flake.nix +++ b/flake.nix @@ -179,6 +179,15 @@ ''; }; + test-sql = { + description = "Run the SQL test file or files"; + packages = cargoRuntime pkgs; + env = cargoEnv pkgs; + script = buildBrowserAssets + '' + SQL_TEST_FILE="''${1:-}" cargo test --test mod sql_test_files + ''; + }; + test-browser = { description = "Drive the components in a browser with Playwright"; packages = cargoRuntime pkgs; diff --git a/tests/sql_test_files/README.md b/tests/sql_test_files/README.md index 6e23b124..1f72f1b4 100644 --- a/tests/sql_test_files/README.md +++ b/tests/sql_test_files/README.md @@ -24,4 +24,12 @@ engine-specific SQL syntax) live in a subdirectory named after that database (`sqlite`, `postgres`, `mysql`, `mssql`, `oracle`, `duckdb`, `snowflake`, `generic`). They are run by a separate test, only when the current database matches. Unlike the other directories, their file names do not need `_no...` -suffixes to exclude incompatible backends. \ No newline at end of file +suffixes to exclude incompatible backends. + +## Running one file + +`SQL_TEST_FILE` limits a run to the files whose path contains its value. The `test-sql` gate sets it from its argument: + +```bash +DATABASE_URL='postgres://root:Password123!@127.0.0.1/sqlpage' nix run .#test-sql -- money_with_parameters_983 +``` diff --git a/tests/sql_test_files/mod.rs b/tests/sql_test_files/mod.rs index 4062d546..7967f37e 100644 --- a/tests/sql_test_files/mod.rs +++ b/tests/sql_test_files/mod.rs @@ -100,12 +100,16 @@ fn read_sql_tests_in_dir(dir: &str, format: SqlTestFormat) -> Vec { let Ok(entries) = std::fs::read_dir(dir) else { return Vec::new(); // no tests in this directory (e.g. no database-specific tests for this database) }; + let selected_name = std::env::var("SQL_TEST_FILE").unwrap_or_default(); entries .filter_map(|e| { let path = e.ok()?.path(); if path.is_dir() || path.extension()? != "sql" { return None; } + if !path.to_string_lossy().contains(&selected_name) { + return None; + } Some(SqlTestCase { path, format }) }) .collect()