forked from extern/nushell
All of the dataframe commands ported over with no issues... ### 11 tests are commented out (for now) So 100 of the original 111 tests are passing with only 11 tests being ignored for now.. As per our conversation in the core team meeting on Wednesday I took @jntrnr suggestion and just commented out the tests dealing with [IntoDatetime](https://github.com/nushell/nushell/blob/main/crates/nu-command/src/conversions/into/mod.rs) Later on we can move this functionality out of nu-command if we decide it makes sense... ### The following tests were ignored... ```rust modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_day.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_hour.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_minute.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_month.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_nanosecond.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_ordinal.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_second.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_week.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_weekday.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/date/get_year.rs modified: crates/nu-cmd-dataframe/src/dataframe/series/string/strftime.rs ```
95 lines
3.0 KiB
Rust
95 lines
3.0 KiB
Rust
use nu_engine::eval_block;
|
|
use nu_parser::parse;
|
|
use nu_protocol::{
|
|
engine::{Command, EngineState, Stack, StateWorkingSet},
|
|
PipelineData, Span,
|
|
};
|
|
|
|
use super::eager::ToDataFrame;
|
|
use super::expressions::ExprCol;
|
|
use super::lazy::{LazyCollect, ToLazyFrame};
|
|
use nu_cmd_lang::Let;
|
|
|
|
pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
|
|
if cmds.is_empty() {
|
|
panic!("Empty commands vector")
|
|
}
|
|
|
|
// The first element in the cmds vector must be the one tested
|
|
let examples = cmds[0].examples();
|
|
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);
|
|
working_set.add_decl(Box::new(Let));
|
|
working_set.add_decl(Box::new(ToDataFrame));
|
|
working_set.add_decl(Box::new(ToLazyFrame));
|
|
working_set.add_decl(Box::new(LazyCollect));
|
|
working_set.add_decl(Box::new(ExprCol));
|
|
|
|
// Adding the command that is being tested to the working set
|
|
for cmd in cmds.clone() {
|
|
working_set.add_decl(cmd);
|
|
}
|
|
|
|
working_set.render()
|
|
};
|
|
|
|
engine_state
|
|
.merge_delta(delta)
|
|
.expect("Error merging delta");
|
|
|
|
for example in examples {
|
|
// Skip tests that don't have results to compare to
|
|
if example.result.is_none() {
|
|
continue;
|
|
}
|
|
let start = std::time::Instant::now();
|
|
|
|
let (block, delta) = {
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
|
let output = parse(&mut working_set, None, example.example.as_bytes(), false);
|
|
|
|
if let Some(err) = working_set.parse_errors.first() {
|
|
panic!("test parse error in `{}`: {:?}", example.example, err)
|
|
}
|
|
|
|
(output, working_set.render())
|
|
};
|
|
|
|
engine_state
|
|
.merge_delta(delta)
|
|
.expect("Error merging delta");
|
|
|
|
let mut stack = Stack::new();
|
|
|
|
let result = eval_block(
|
|
&engine_state,
|
|
&mut stack,
|
|
&block,
|
|
PipelineData::empty(),
|
|
true,
|
|
true,
|
|
)
|
|
.unwrap_or_else(|err| panic!("test eval error in `{}`: {:?}", example.example, err))
|
|
.into_value(Span::test_data());
|
|
|
|
println!("input: {}", example.example);
|
|
println!("result: {result:?}");
|
|
println!("done: {:?}", start.elapsed());
|
|
|
|
// Note. Value implements PartialEq for Bool, Int, Float, String and Block
|
|
// If the command you are testing requires to compare another case, then
|
|
// you need to define its equality in the Value struct
|
|
if let Some(expected) = example.result {
|
|
if result != expected {
|
|
panic!(
|
|
"the example result is different to expected value: {result:?} != {expected:?}"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|