process_tools 0.31.0

Collection of algorithms and structures to handle processes properly.
Documentation
use super :: *;
use the_module ::process;
use std ::
{
  env ::consts ::EXE_EXTENSION,
  path ::{ Path, PathBuf },
  process ::Command,
};

#[ path = "../tool/asset.rs" ]
mod asset;

/// Compile a single-file Rust source and return the path of the produced binary.
pub fn asset_binary_path( name : &Path, temp_path : &Path ) -> PathBuf
{
  _ = Command ::new( "rustc" ).current_dir( temp_path ).arg( name ).status().unwrap();

  PathBuf ::from( temp_path )
  .join( name.file_name().unwrap() )
  .with_extension( EXE_EXTENSION )
}

#[ test ]
fn err_out_err()
{
  let temp = assert_fs ::TempDir ::new().unwrap();
  let assets_path = asset ::path().unwrap();

  let options = process ::Run ::former()
  .bin_path( asset_binary_path(
    &assets_path.join( "err_out_test" ).join( "err_out_err.rs" ),
    temp.path(),
  ))
  .current_path( temp.to_path_buf() )
  .joining_streams( true )
  .form();

  let report = process ::run( options ).unwrap();

  println!( "{report}" );

  assert_eq!( "This is stderr text\nThis is stdout text\nThis is stderr text\n", report.out );
}

#[ test ]
fn out_err_out()
{
  let temp = assert_fs ::TempDir ::new().unwrap();
  let assets_path = asset ::path().unwrap();

  let options = process ::Run ::former()
  .bin_path( asset_binary_path(
    &assets_path.join( "err_out_test" ).join( "out_err_out.rs" ),
    temp.path(),
  ))
  .current_path( temp.to_path_buf() )
  .joining_streams( true )
  .form();

  let report = process ::run( options ).unwrap();

  assert_eq!( "This is stdout text\nThis is stderr text\nThis is stdout text\n", report.out );
}