forked from extern/nushell
This PR reverts https://github.com/nushell/nushell/pull/9391 We try not to revert PRs like this, though after discussion with the Nushell team, we decided to revert this one. The main reason is that Nushell, as a codebase, isn't ready for these kinds of optimisations. It's in the part of the development cycle where our main focus should be on improving the algorithms inside of Nushell itself. Once we have matured our algorithms, then we can look for opportunities to switch out technologies we're using for alternate forms. Much of Nushell still has lots of opportunities for tuning the codebase, paying down technical debt, and making the codebase generally cleaner and more robust. This should be the focus. Performance improvements should flow out of that work. Said another, optimisation that isn't part of tuning the codebase is premature at this stage. We need to focus on doing the hard work of making the engine, parser, etc better. # User-Facing Changes Reverts the HashMap -> ahash change. cc @FilipAndersson245
75 lines
2.4 KiB
Rust
75 lines
2.4 KiB
Rust
#[cfg(test)]
|
|
use nu_protocol::engine::Command;
|
|
|
|
#[cfg(test)]
|
|
pub fn test_examples(cmd: impl Command + 'static) {
|
|
test_examples::test_examples(cmd);
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test_examples {
|
|
|
|
use nu_cmd_lang::example_support::{
|
|
check_all_signature_input_output_types_entries_have_examples,
|
|
check_example_evaluates_to_expected_output,
|
|
check_example_input_and_output_types_match_command_signature,
|
|
};
|
|
|
|
use nu_protocol::{
|
|
engine::{Command, EngineState, StateWorkingSet},
|
|
Type,
|
|
};
|
|
use std::collections::HashSet;
|
|
|
|
pub fn test_examples(cmd: impl Command + 'static) {
|
|
let examples = cmd.examples();
|
|
let signature = cmd.signature();
|
|
let mut engine_state = make_engine_state(cmd.clone_box());
|
|
|
|
let cwd = std::env::current_dir().expect("Could not get current working directory.");
|
|
|
|
let mut witnessed_type_transformations = HashSet::<(Type, Type)>::new();
|
|
|
|
for example in examples {
|
|
if example.result.is_none() {
|
|
continue;
|
|
}
|
|
witnessed_type_transformations.extend(
|
|
check_example_input_and_output_types_match_command_signature(
|
|
&example,
|
|
&cwd,
|
|
&mut make_engine_state(cmd.clone_box()),
|
|
&signature.input_output_types,
|
|
signature.operates_on_cell_paths(),
|
|
signature.vectorizes_over_list,
|
|
),
|
|
);
|
|
check_example_evaluates_to_expected_output(&example, cwd.as_path(), &mut engine_state);
|
|
}
|
|
|
|
check_all_signature_input_output_types_entries_have_examples(
|
|
signature,
|
|
witnessed_type_transformations,
|
|
);
|
|
}
|
|
|
|
fn make_engine_state(cmd: Box<dyn Command>) -> Box<EngineState> {
|
|
let mut engine_state = Box::new(EngineState::new());
|
|
|
|
let delta = {
|
|
// Base functions that are needed for testing
|
|
// Try to keep this working set small to keep tests running as fast as possible
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
|
|
|
// Adding the command that is being tested to the working set
|
|
working_set.add_decl(cmd);
|
|
working_set.render()
|
|
};
|
|
|
|
engine_state
|
|
.merge_delta(delta)
|
|
.expect("Error merging delta");
|
|
engine_state
|
|
}
|
|
}
|