You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found while working on #80. Pre-existing on main, independent of that change.
Reproduce
cargo test --lib sql_injection
Observed
error: unexpected argument '--nocapture' found
tip: a similar argument exists: '--no-tcp'
Usage: <test-binary> --no-tcp
error: test failed
or, with a bare filter, the process exits non-zero before running the matched tests.
Cause
config::CONFIG is a lazy_static whose initializer calls Config::load() → Config::parse() (src/config.rs). In a test binary, argv belongs to the libtest harness, not to pgsqlite, so clap sees --nocapture or a filter string, rejects it, and calls process::exit.
Anything that touches CONFIG in a test binary triggers this. db_handler::tests::test_sql_injection_patterns constructs a DbHandler, which initializes lazy statics that dereference CONFIG — src/session/state.rs:15, src/cache/statement_pool.rs:35, src/cache/execution.rs:130, src/cache/result_cache.rs:246.
Impact
cargo test -- --nocapture is unusable for any test that reaches CONFIG, which is most integration tests, since session creation initializes those caches. This makes debugging test failures materially harder.
Any cargo test --lib <filter> whose filter matches those db_handler tests aborts rather than running.
Have Config::load() fall back to Config::parse_from(["pgsqlite"]) (defaults only) when running under a test harness — detectable via cfg!(test) for lib tests, though not for integration test binaries.
Or use try_parse() and fall back to defaults on error instead of exiting, at least when argv[0] is not the pgsqlite binary.
Or make the tests that construct a DbHandler inject a Config rather than relying on the global.
Found while working on #80. Pre-existing on
main, independent of that change.Reproduce
cargo test --lib sql_injectionObserved
or, with a bare filter, the process exits non-zero before running the matched tests.
Cause
config::CONFIGis alazy_staticwhose initializer callsConfig::load()→Config::parse()(src/config.rs). In a test binary,argvbelongs to the libtest harness, not to pgsqlite, so clap sees--nocaptureor a filter string, rejects it, and callsprocess::exit.Anything that touches
CONFIGin a test binary triggers this.db_handler::tests::test_sql_injection_patternsconstructs aDbHandler, which initializes lazy statics that dereferenceCONFIG—src/session/state.rs:15,src/cache/statement_pool.rs:35,src/cache/execution.rs:130,src/cache/result_cache.rs:246.Impact
cargo test -- --nocaptureis unusable for any test that reachesCONFIG, which is most integration tests, since session creation initializes those caches. This makes debugging test failures materially harder.cargo test --lib <filter>whose filter matches thosedb_handlertests aborts rather than running.AtomicBoolset frommainrather than readingCONFIGat the call sites, purely so the feature would be testable.Possible fixes
Config::load()fall back toConfig::parse_from(["pgsqlite"])(defaults only) when running under a test harness — detectable viacfg!(test)for lib tests, though not for integration test binaries.try_parse()and fall back to defaults on error instead of exiting, at least whenargv[0]is not the pgsqlite binary.DbHandlerinject aConfigrather than relying on the global.