Skip to content

Commit

Permalink
Merge pull request #1227 from SRetip/table_and_progress_fix
Browse files Browse the repository at this point in the history
READY(willbe/`.test`) : Table and progress fix
  • Loading branch information
Wandalen authored Mar 21, 2024
2 parents cd06dee + 766185c commit ace68be
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 36 deletions.
16 changes: 14 additions & 2 deletions module/move/willbe/src/action/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ mod private
optimizations : HashSet< optimization::Optimization >,
#[ default( 1000u32 ) ]
variants_cap : u32,
#[ default( false ) ]
with_progress : bool,
}


/// The function runs tests with a different set of features in the selected crate (the path to the crate is specified in the dir variable).
/// Tests are run with each feature separately, with all features together, and without any features.
Expand Down Expand Up @@ -127,7 +130,8 @@ mod private
with_all_features,
with_none_features,
optimizations,
variants_cap,
variants_cap,
with_progress,
} = args;

let packages = needed_packages( args.dir.clone() ).map_err( | e | ( reports.clone(), e ) )?;
Expand Down Expand Up @@ -183,7 +187,15 @@ mod private
.dry( dry );

#[ cfg( feature = "progress_bar" ) ]
let test_options_former = test_options_former.feature( TestOptionsProgressBarFeature{ multiprocess, style } );
let test_options_former = if with_progress
{
let test_options_former = test_options_former.feature( TestOptionsProgressBarFeature{ multiprocess, style } );
test_options_former
}
else
{
test_options_former
};

let options = test_options_former.form();
let result = tests_run( &options );
Expand Down
5 changes: 5 additions & 0 deletions module/move/willbe/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ pub( crate ) mod private
.kind( Type::Number )
.optional( true )
.end()
.property( "with_progress" )
.hint( "If true, will display progressbar during the tests. Default is `true`. ! Work only with `progress_bar` feature !")
.kind( Type::Bool )
.optional( true )
.end()
.routine( command::test )
.end()

Expand Down
7 changes: 6 additions & 1 deletion module/move/willbe/src/command/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ mod private
with_debug : bool,
#[ default( false ) ]
with_release : bool,
#[ default( true ) ]
with_progress : bool,
}

/// run tests in specified crate
Expand All @@ -62,7 +64,8 @@ mod private
with_all_features,
with_none_features,
with_debug,
with_release
with_release,
with_progress
} = properties.try_into()?;

let mut channels = HashSet::new();
Expand Down Expand Up @@ -91,6 +94,7 @@ mod private
.with_all_features( with_all_features )
.with_none_features( with_none_features )
.optimizations( optimizations )
.with_progress( with_progress )
.form();

match action::test( args, dry )
Expand Down Expand Up @@ -129,6 +133,7 @@ mod private
this = if let Some( v ) = value.get_owned( "with_all_features" ) { this.with_all_features::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_none_features" ) { this.with_none_features::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "always" ) { this.enabled_features::< Vec< String > >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_progress" ) { this.with_progress::< bool >( v ) } else { this };

Ok( this.form() )
}
Expand Down
93 changes: 60 additions & 33 deletions module/move/willbe/src/entity/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,26 @@ mod private
// qqq : for Petro : don't use cargo_metadata directly, use facade
use colored::Colorize;
// qqq : for Petro : don't do micro imports
use prettytable::{ Cell, Row, Table };
use prettytable::
{
Cell,
Row,
Table,
};
// qqq : for Petro : don't do micro imports
#[ cfg( feature = "progress_bar" ) ]
use indicatif::{ MultiProgress, ProgressBar, ProgressStyle };
use prettytable::format::{ FormatBuilder, TableFormat };
use indicatif::
{
MultiProgress,
ProgressBar,
ProgressStyle
};
use prettytable::format::
{
Alignment,
FormatBuilder,
TableFormat
};
use rayon::ThreadPoolBuilder;
use process_tools::process::*;
use wtools::error::anyhow::{ Error, format_err };
Expand Down Expand Up @@ -177,18 +192,21 @@ mod private
let mut a = true;
for feature in &all_features
{
let mut c = Cell::new( "+" );
c.align( Alignment::CENTER );
if variant.features.is_empty() && a
{
a = false;
row.add_cell( Cell::new( "+" ) );
row.add_cell( c );
}
else if variant.features.contains( feature )
{
row.add_cell( Cell::new( "+" ) );
row.add_cell( c );
}
else
{
row.add_cell( Cell::new( "" ) );
c = Cell::new( "" );
row.add_cell( c );
}
}

Expand Down Expand Up @@ -299,9 +317,9 @@ mod private
{
phantom : PhantomData< &'a () >,
#[ cfg( feature = "progress_bar" ) ]
multi_progress : &'a MultiProgress,
multi_progress : &'a Option< &'a MultiProgress >,
#[ cfg( feature = "progress_bar" ) ]
progress_bar : &'a ProgressBar
progress_bar : &'a Option< ProgressBar >
}


Expand Down Expand Up @@ -509,7 +527,6 @@ mod private
let mut table = Table::new();
let format = format();
table.set_format( format );
table.set_format( *prettytable::format::consts::FORMAT_NO_BORDER );
let mut all_features = BTreeSet::new();
for variant in self.tests.keys()
{
Expand Down Expand Up @@ -563,18 +580,21 @@ mod private
let mut a = true;
for feature in &all_features
{
let mut c = Cell::new( "+" );
c.align( Alignment::CENTER );
if variant.features.is_empty() && a
{
a = false;
row.add_cell( Cell::new( "+" ) );
row.add_cell( c );
}
else if variant.features.contains( feature )
{
row.add_cell( Cell::new( "+" ) );
row.add_cell( c );
}
else
{
row.add_cell( Cell::new( "" ) );
c = Cell::new( "" );
row.add_cell( c );
}
}

Expand Down Expand Up @@ -623,7 +643,7 @@ mod private
pub failure_reports : Vec< TestReport >,
}

impl std::fmt::Display for TestsReport
impl Display for TestsReport
{
fn fmt( &self, f : &mut Formatter< '_ > ) -> std::fmt::Result
{
Expand Down Expand Up @@ -692,36 +712,33 @@ mod private

if let Some( p ) = options.temp_path.clone()
{
// let path = p.join
// (
// format!
// (
// "{}_{}_{}_{}",
// options.plan.package.file_name().unwrap().to_string_lossy(),
// optimization,
// channel,
// features.iter().join( "," )
// )
// );
let path = p.join( path_tools::path::unique_folder_name().unwrap() );
// let path = p.join( path_tools::path::unique_folder_name().err_with( || report.clone() ).unwrap() );
// qqq : for Petro : rid off unwrap
std::fs::create_dir_all( &path ).unwrap();
args_t = args_t.temp_directory_path( path );
}
#[ cfg( feature = "progress_bar" ) ]
let _s =
{
let spinner = options.progress_bar_feature.as_ref().unwrap().multi_progress.add( ProgressBar::new_spinner().with_message( format!( "{}", variant ) ) );
spinner.enable_steady_tick( std::time::Duration::from_millis( 100 ) );
spinner
let s = if let Some( multi_progress ) = options.progress_bar_feature.as_ref().and_then( | f | f.multi_progress.as_ref() )
{
let s = multi_progress.add( ProgressBar::new_spinner().with_message( format!( "{}", variant ) ) );
s.enable_steady_tick( std::time::Duration::from_millis( 100 ) );
Some( s )
}
else
{
None
};
// spinner.enable_steady_tick( std::time::Duration::from_millis( 100 ) );
s
};
let args = args_t.form();
let temp_dir = args.temp_directory_path.clone();
let cmd_rep = _run( dir, args );
r.lock().unwrap().tests.insert( variant.clone(), cmd_rep );
#[ cfg( feature = "progress_bar" ) ]
options.progress_bar_feature.as_ref().unwrap().progress_bar.inc( 1 );
options.progress_bar_feature.as_ref().unwrap().progress_bar.as_ref().map( | b | b.inc( 1 ) );
if let Some( path ) = temp_dir
{
std::fs::remove_dir_all( path ).unwrap();
Expand Down Expand Up @@ -762,19 +779,29 @@ mod private
#[ cfg( feature = "progress_bar" ) ]
let pb =
{
let pb = args.feature.as_ref().unwrap().multiprocess.add( ProgressBar::new( plan.test_variants.len() as u64 ) );
pb.set_style( args.feature.as_ref().unwrap().style.clone() );
pb.inc( 0 );
let pb = if let Some( feature ) = args.feature.as_ref()
{
let pb = feature.multiprocess.add(ProgressBar::new(plan.test_variants.len() as u64));
pb.set_style( args.feature.as_ref().unwrap().style.clone() );
pb.inc( 0 );
Some( pb )
}
else
{
None
};
pb
};
#[ cfg( feature = "progress_bar" ) ]
let multi_progress = args.feature.as_ref().map( | f | &f.multiprocess );
let test_package_options = PackageTestOptions::former().option_temp( args.temp_path.clone() ).plan( plan ).dry( args.dry );
#[ cfg( feature = "progress_bar" ) ]
let test_package_options = test_package_options.progress_bar_feature
(
PackageTestOptionsProgressBarFeature
{
phantom : PhantomData,
multi_progress : &args.feature.as_ref().unwrap().multiprocess,
multi_progress : &multi_progress,
progress_bar : &pb,
}
);
Expand Down
1 change: 1 addition & 0 deletions module/move/willbe/tests/inc/action/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ fn plan()
.channels([ Channel::Stable, Channel::Nightly ])
.optimizations([ Optimization::Debug, Optimization::Release ])
.with_none_features( true )
.with_progress( false )
.form();

let rep = test( args, true ).unwrap().succses_reports[ 0 ].clone().tests;
Expand Down

0 comments on commit ace68be

Please sign in to comment.