2022-02-04 03:01:45 +01:00
|
|
|
use nu_command::create_default_context;
|
2023-04-21 21:00:33 +02:00
|
|
|
use nu_protocol::{engine::StateWorkingSet, Category, Span};
|
2021-07-01 00:47:56 +02:00
|
|
|
use quickcheck_macros::quickcheck;
|
2020-03-04 19:58:20 +01:00
|
|
|
|
|
|
|
mod commands;
|
|
|
|
mod format_conversions;
|
2021-07-01 00:47:56 +02:00
|
|
|
|
2022-02-04 03:01:45 +01:00
|
|
|
#[quickcheck]
|
|
|
|
fn quickcheck_parse(data: String) -> bool {
|
|
|
|
let (tokens, err) = nu_parser::lex(data.as_bytes(), 0, b"", b"", true);
|
|
|
|
|
2022-11-18 22:46:48 +01:00
|
|
|
if err.is_none() {
|
2022-07-14 16:09:27 +02:00
|
|
|
let context = create_default_context();
|
2022-02-04 03:01:45 +01:00
|
|
|
{
|
|
|
|
let mut working_set = StateWorkingSet::new(&context);
|
2023-04-09 22:55:47 +02:00
|
|
|
let _ = working_set.add_file("quickcheck".into(), data.as_bytes());
|
2022-02-04 03:01:45 +01:00
|
|
|
|
2023-04-21 21:00:33 +02:00
|
|
|
let _ =
|
|
|
|
nu_parser::parse_block(&mut working_set, &tokens, Span::new(0, 0), false, false);
|
2022-02-04 03:01:45 +01:00
|
|
|
}
|
2021-07-01 00:47:56 +02:00
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
2022-08-24 11:16:47 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn signature_name_matches_command_name() {
|
|
|
|
let ctx = crate::create_default_context();
|
2022-12-30 16:44:37 +01:00
|
|
|
let decls = ctx.get_decls_sorted(true);
|
2022-08-24 11:16:47 +02:00
|
|
|
let mut failures = Vec::new();
|
|
|
|
|
2022-12-30 16:44:37 +01:00
|
|
|
for (name_bytes, decl_id) in decls {
|
2022-08-24 11:16:47 +02:00
|
|
|
let cmd = ctx.get_decl(decl_id);
|
2022-12-30 16:44:37 +01:00
|
|
|
let cmd_name = String::from_utf8_lossy(&name_bytes);
|
2022-08-24 11:16:47 +02:00
|
|
|
let sig_name = cmd.signature().name;
|
|
|
|
let category = cmd.signature().category;
|
|
|
|
|
|
|
|
if cmd_name != sig_name {
|
|
|
|
failures.push(format!(
|
|
|
|
"{cmd_name} ({category:?}): Signature name \"{sig_name}\" is not equal to the command name \"{cmd_name}\""
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
failures.is_empty(),
|
|
|
|
"Name mismatch:\n{}",
|
|
|
|
failures.join("\n")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-21 20:20:46 +01:00
|
|
|
#[test]
|
|
|
|
fn commands_declare_input_output_types() {
|
|
|
|
let ctx = crate::create_default_context();
|
2022-12-30 16:44:37 +01:00
|
|
|
let decls = ctx.get_decls_sorted(true);
|
2022-12-21 20:20:46 +01:00
|
|
|
let mut failures = Vec::new();
|
|
|
|
|
2022-12-30 16:44:37 +01:00
|
|
|
for (_, decl_id) in decls {
|
2022-12-21 20:20:46 +01:00
|
|
|
let cmd = ctx.get_decl(decl_id);
|
|
|
|
let sig_name = cmd.signature().name;
|
|
|
|
let category = cmd.signature().category;
|
|
|
|
|
|
|
|
if matches!(category, Category::Deprecated | Category::Custom(_)) {
|
|
|
|
// Deprecated commands don't have to conform
|
|
|
|
// TODO: also upgrade the `--features dataframe` commands
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.signature().input_output_types.is_empty() {
|
|
|
|
failures.push(format!(
|
|
|
|
"{sig_name} ({category:?}): No pipeline input/output type signatures found"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
failures.is_empty(),
|
|
|
|
"Command missing type annotations:\n{}",
|
|
|
|
failures.join("\n")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:16:47 +02:00
|
|
|
#[test]
|
|
|
|
fn no_search_term_duplicates() {
|
|
|
|
let ctx = crate::create_default_context();
|
2022-12-30 16:44:37 +01:00
|
|
|
let decls = ctx.get_decls_sorted(true);
|
2022-08-24 11:16:47 +02:00
|
|
|
let mut failures = Vec::new();
|
|
|
|
|
2022-12-30 16:44:37 +01:00
|
|
|
for (name_bytes, decl_id) in decls {
|
2022-08-24 11:16:47 +02:00
|
|
|
let cmd = ctx.get_decl(decl_id);
|
2022-12-30 16:44:37 +01:00
|
|
|
let cmd_name = String::from_utf8_lossy(&name_bytes);
|
2022-08-24 11:16:47 +02:00
|
|
|
let search_terms = cmd.search_terms();
|
|
|
|
let category = cmd.signature().category;
|
|
|
|
|
|
|
|
for search_term in search_terms {
|
|
|
|
if cmd_name.contains(search_term) {
|
|
|
|
failures.push(format!("{cmd_name} ({category:?}): Search term \"{search_term}\" is substring of command name \"{cmd_name}\""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
failures.is_empty(),
|
|
|
|
"Duplication in search terms:\n{}",
|
|
|
|
failures.join("\n")
|
|
|
|
);
|
|
|
|
}
|