diff --git a/Cargo.lock b/Cargo.lock index 7d8a62809..86c8fdc51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2098,6 +2098,8 @@ dependencies = [ "prettytable-rs", "ptree", "query_interface", + "quickcheck", + "quickcheck_macros", "rand", "regex", "roxmltree", @@ -2848,6 +2850,29 @@ dependencies = [ "memchr", ] +[[package]] +name = "quickcheck" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f" +dependencies = [ + "env_logger", + "log", + "rand", + "rand_core", +] + +[[package]] +name = "quickcheck_macros" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608c156fd8e97febc07dc9c2e2c80bf74cfc6ef26893eae3daf8bc2bc94a4b7f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quote" version = "1.0.2" diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index cfeb333d0..7cc52a448 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -97,6 +97,10 @@ features = ["bundled", "blob"] [build-dependencies] nu-build = { version = "0.12.0", path = "../nu-build" } +[dev-dependencies] +quickcheck = "0.9" +quickcheck_macros = "0.9" + [features] stable = [] starship-prompt = ["starship"] diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 31acc8b2d..19f3cb8a9 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -776,3 +776,19 @@ pub fn print_err(err: ShellError, host: &dyn Host, source: &Text) { ); }); } + +#[cfg(test)] +mod tests { + + #[quickcheck] + fn quickcheck_parse(data: String) -> bool { + if let Ok(lite_pipeline) = nu_parser::lite_parse(&data, 0) { + let context = crate::context::Context::basic().unwrap(); + nu_parser::classify_pipeline(&lite_pipeline, context.registry()) + .failed + .is_none() + } else { + false + } + } +} diff --git a/crates/nu-cli/src/lib.rs b/crates/nu-cli/src/lib.rs index 9c4cf2d1b..23c070f9a 100644 --- a/crates/nu-cli/src/lib.rs +++ b/crates/nu-cli/src/lib.rs @@ -7,6 +7,12 @@ extern crate indexmap; #[macro_use] mod prelude; +#[cfg(test)] +extern crate quickcheck; +#[cfg(test)] +#[macro_use(quickcheck)] +extern crate quickcheck_macros; + mod cli; mod commands; mod context;