Skip to content

Commit

Permalink
Merge branch 'alpha' of github.com:Wandalen/wTools into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 21, 2024
2 parents 6655ef8 + 8dacebf commit fed47e3
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto_merge_to_beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs :
- uses: actions/checkout@v3
- id: workflow_files
run: |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
NAME=$(echo $WORKFLOW | sed 's/\(\S\+\).yml/\1/')
NAMES="$NAMES $NAME"
Expand All @@ -31,7 +31,7 @@ jobs :
echo "files={\"modules\":$OUTPUT}" >> $GITHUB_OUTPUT
- id: workflow_names
run: |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
NAME=$(cat .github/workflows/$WORKFLOW | grep -G '^name :' | sed 's/name\s*:\s\+\(\S*\)/\1/')
NAMES="$NAMES%0A$NAME"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/status_checks_rules_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs :
- name : Get options
id : options_get
run : |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
CONTEXT=$(echo $WORKFLOW | sed 's/\(\S\+\).yml/{"context":"check (\1)","app_id":null}/')
CONTEXTS="$CONTEXTS,$CONTEXT"
Expand Down
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
4 changes: 2 additions & 2 deletions module/move/willbe/template/workflow/auto_merge_to.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs :
- uses: actions/checkout@v3
- id: workflow_files
run: |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
NAME=$(echo $WORKFLOW | sed 's/\(\S\+\).yml/\1/')
NAMES="$NAMES $NAME"
Expand All @@ -31,7 +31,7 @@ jobs :
echo "files={\"modules\":$OUTPUT}" >> $GITHUB_OUTPUT
- id: workflow_names
run: |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
NAME=$(cat .github/workflows/$WORKFLOW | grep -G '^name :' | sed 's/name\s*:\s\+\(\S*\)/\1/')
NAMES="$NAMES%0A$NAME"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs :
- name : Get options
id : options_get
run : |
WORKFLOWS=$(ls .github/workflows | grep Module)
WORKFLOWS=$(ls .github/workflows | grep module)
for WORKFLOW in $WORKFLOWS ; do
CONTEXT=$(echo $WORKFLOW | sed 's/\(\S\+\).yml/{"context":"check (\1)","app_id":null}/')
CONTEXTS="$CONTEXTS,$CONTEXT"
Expand Down
38 changes: 38 additions & 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 All @@ -181,6 +182,43 @@ fn plan()
assert!( rep.get( &TestVariant::former().optimization( Optimization::Release ).channel( Channel::Nightly ).features( BTreeSet::default() ).form() ).is_some() );
}

#[ test ]
fn backtrace_should_be()
{
let temp = TempDir::new().unwrap();
let temp = &temp;

let project = ProjectBuilder::new( "fail_build" )
.toml_file( "[features]\nenabled = []" )
.test_file( r#"
#[test]
fn fail() {
assert!(false);
}
"#)
.build( temp )
.unwrap();
let abs = AbsolutePath::try_from( project ).unwrap();

let args = TestsCommandOptions::former()
.dir( abs )
.channels([ Channel::Stable ])
.optimizations([ Optimization::Debug ])
.with_none_features( true )
.form();

let rep = test( args, false ).unwrap_err().0;
println!( "========= OUTPUT =========\n{}\n==========================", rep );

let no_features = rep
.failure_reports[ 0 ]
.tests.get( &TestVariant::former().optimization( Optimization::Debug ).channel( Channel::Stable ).features( BTreeSet::default() ).form() )
.unwrap();

assert!( !no_features.clone().unwrap_err().out.contains( "RUST_BACKTRACE" ) );
assert!( no_features.clone().unwrap_err().out.contains( "stack backtrace" ) );
}

#[ derive( Debug ) ]
pub struct ProjectBuilder
{
Expand Down

0 comments on commit fed47e3

Please sign in to comment.