Skip to main content

sqry_cli/
lib.rs

1//! sqry-cli library exports
2//!
3//! This module exists to make certain functionality available to integration tests
4//! and benchmarks. The main binary is still in `main.rs`.
5
6pub mod args;
7pub mod commands;
8pub mod error;
9pub mod index_discovery;
10pub mod output;
11pub mod persistence;
12pub mod plugin_defaults;
13pub mod progress;
14
15/// Wrap a `#[test]` body in a 16 MB-stack thread.
16///
17/// Clap's deep subcommand tree causes `Cli::parse_from` to overflow the
18/// default 8 MB debug-mode thread stack via deep recursion (not enum size).
19/// Use this macro around any test that constructs a `Cli` value.
20///
21/// ```ignore
22/// large_stack_test! {
23///     #[test]
24///     fn my_test() {
25///         let cli = Cli::parse_from(["sqry", "index"]);
26///         assert!(cli.command.is_some());
27///     }
28/// }
29/// ```
30#[cfg(test)]
31macro_rules! large_stack_test {
32    ($(#[$attr:meta])* fn $name:ident() $body:block) => {
33        $(#[$attr])*
34        fn $name() {
35            let result = std::thread::Builder::new()
36                .stack_size(16 * 1024 * 1024)
37                .spawn(move || $body)
38                .expect("spawn test thread")
39                .join();
40            if let Err(panic) = result {
41                std::panic::resume_unwind(panic);
42            }
43        }
44    };
45}
46#[cfg(test)]
47pub(crate) use large_stack_test;