#[ allow( unused_imports ) ]
use super::*;
#[ test ]
fn source_empty_file_path()
{
use the_module::program;
let source = program::Source::former()
.file_path( "" )
.data( "fn main() {}" )
.form();
assert_eq!( source.file_path, "" );
assert_eq!( source.data, "fn main() {}" );
}
#[ test ]
fn source_empty_data()
{
use the_module::program;
let source = program::Source::former()
.file_path( "main.rs" )
.data( "" )
.form();
assert_eq!( source.file_path, "main.rs" );
assert_eq!( source.data, "" );
}
#[ test ]
fn source_both_fields_empty()
{
use the_module::program;
let source = program::Source::former()
.file_path( "" )
.data( "" )
.form();
assert_eq!( source.file_path, "" );
assert_eq!( source.data, "" );
}
#[ test ]
fn source_large_data()
{
use the_module::program;
let large_data = "// comment\n".repeat( 50_000 ); let expected_len = large_data.len();
let source = program::Source::former()
.file_path( "large.rs" )
.data( &large_data )
.form();
assert_eq!( source.file_path, "large.rs" );
assert_eq!( source.data.len(), expected_len );
assert!( source.data.starts_with( "// comment\n" ) );
}
#[ test ]
fn source_special_characters()
{
use the_module::program;
let source = program::Source::former()
.file_path( "src/模块.rs" ) .data( "fn main() {\n\tprintln!(\"🦀 Rust\");\n}" )
.form();
assert_eq!( source.file_path, "src/模块.rs" );
assert_eq!( source.data, "fn main() {\n\tprintln!(\"🦀 Rust\");\n}" );
assert!( source.data.contains( "🦀" ) ); assert!( source.data.contains( '\t' ) ); assert!( source.data.contains( '\n' ) ); }
#[ test ]
fn program_zero_sources()
{
use the_module::program;
let program = program::Program::former().form();
assert_eq!( program.source.len(), 0 );
assert!( program.source.is_empty() );
}
#[ test ]
fn program_single_source()
{
use the_module::program;
let program = program::Program::former()
.source()
.file_path( "main.rs" )
.data( "fn main() {}" )
.end()
.form();
assert_eq!( program.source.len(), 1 );
assert_eq!( program.source[ 0 ].file_path, "main.rs" );
assert_eq!( program.source[ 0 ].data, "fn main() {}" );
}
#[ test ]
fn program_duplicate_file_paths()
{
use the_module::program;
let program = program::Program::former()
.source()
.file_path( "main.rs" )
.data( "// version 1" )
.end()
.source()
.file_path( "main.rs" ) .data( "// version 2" )
.end()
.form();
assert_eq!( program.source.len(), 2 );
assert_eq!( program.source[ 0 ].file_path, "main.rs" );
assert_eq!( program.source[ 1 ].file_path, "main.rs" );
assert_eq!( program.source[ 0 ].data, "// version 1" );
assert_eq!( program.source[ 1 ].data, "// version 2" );
}
#[ test ]
fn program_three_sources()
{
use the_module::program;
let program = program::Program::former()
.source()
.file_path( "a.rs" )
.data( "// a" )
.end()
.source()
.file_path( "b.rs" )
.data( "// b" )
.end()
.source()
.file_path( "c.rs" )
.data( "// c" )
.end()
.form();
assert_eq!( program.source.len(), 3 );
assert_eq!( program.source[ 0 ].file_path, "a.rs" );
assert_eq!( program.source[ 1 ].file_path, "b.rs" );
assert_eq!( program.source[ 2 ].file_path, "c.rs" );
}
#[ test ]
fn program_insertion_order_preserved()
{
use the_module::program;
let program = program::Program::former()
.source()
.file_path( "first.rs" )
.data( "// first" )
.end()
.source()
.file_path( "second.rs" )
.data( "// second" )
.end()
.source()
.file_path( "third.rs" )
.data( "// third" )
.end()
.form();
assert_eq!( program.source[ 0 ].file_path, "first.rs" );
assert_eq!( program.source[ 1 ].file_path, "second.rs" );
assert_eq!( program.source[ 2 ].file_path, "third.rs" );
}
#[ test ]
fn plan_minimal_with_empty_program()
{
use the_module::program;
let plan = program::Plan::former()
.program()
.end()
.form();
assert_eq!( plan.program.source.len(), 0 );
assert!( plan.program.source.is_empty() );
}
#[ test ]
fn debug_trait_all_structs()
{
use the_module::program;
let source = program::Source::former()
.file_path( "test.rs" )
.data( "code" )
.form();
let program = program::Program::former()
.source()
.file_path( "main.rs" )
.data( "fn main() {}" )
.end()
.form();
let plan = program::Plan::former()
.program()
.source()
.file_path( "lib.rs" )
.data( "pub fn test() {}" )
.end()
.end()
.form();
let source_debug = format!( "{source:?}" );
let program_debug = format!( "{program:?}" );
let plan_debug = format!( "{plan:?}" );
assert!( !source_debug.is_empty() );
assert!( !program_debug.is_empty() );
assert!( !plan_debug.is_empty() );
assert!( source_debug.contains( "Source" ) );
assert!( program_debug.contains( "Program" ) );
assert!( plan_debug.contains( "Plan" ) );
}
#[ test ]
fn namespace_exposed_module_imports()
{
use the_module::program;
let _source: program::Source = program::Source::former()
.file_path( "test.rs" )
.data( "code" )
.form();
let _program: program::Program = program::Program::former()
.form();
let _plan: program::Plan = program::Plan::former()
.program()
.end()
.form();
}
#[ test ]
fn namespace_prelude_imports()
{
use the_module::prelude::*;
let _source: Source = Source::former()
.file_path( "test.rs" )
.data( "code" )
.form();
let _program: Program = Program::former()
.form();
let _plan: Plan = Plan::former()
.program()
.end()
.form();
}
#[ test ]
fn explicit_form_default_equivalence()
{
use the_module::program;
let source1 = program::Source::former()
.file_path( "test.rs" )
.data( "code" )
.form();
let source2 = program::Source::former()
.file_path( "test.rs" )
.data( "code" )
.form();
assert_eq!( source1.file_path, source2.file_path );
assert_eq!( source1.data, source2.data );
}
#[ test ]
fn explicit_parameters_all_fields()
{
use the_module::program;
let source = program::Source::former()
.file_path( "explicit.rs" )
.data( "explicit data" )
.form();
assert_eq!( source.file_path, "explicit.rs" );
assert_eq!( source.data, "explicit data" );
let program = program::Program::former()
.source()
.file_path( "file1.rs" )
.data( "data1" )
.end()
.source()
.file_path( "file2.rs" )
.data( "data2" )
.end()
.form();
assert_eq!( program.source.len(), 2 );
assert_eq!( program.source[ 0 ].file_path, "file1.rs" );
assert_eq!( program.source[ 1 ].file_path, "file2.rs" );
}
#[ test ]
fn captured_output_default_has_zero_values()
{
use the_module::CapturedOutput;
let out = CapturedOutput::default();
assert_eq!( out.exit_status, 0 );
assert!( out.stdout.is_empty() );
assert!( out.stderr.is_empty() );
}
#[ test ]
fn captured_output_lossy_utf8_stdout()
{
use the_module::CapturedOutput;
let out = CapturedOutput { exit_status : 0, stdout : vec![ 0xFF, 0xFE ], stderr : vec![] };
let decoded = out.stdout_str();
assert!( !decoded.is_empty(), "lossy decode should produce a non-empty string" );
assert!( decoded.contains( '\u{FFFD}' ), "expected replacement char for invalid UTF-8" );
}
#[ test ]
fn captured_output_lossy_utf8_stderr()
{
use the_module::CapturedOutput;
let out = CapturedOutput { exit_status : 1, stdout : vec![], stderr : vec![ 0xC0, 0x80 ] };
let decoded = out.stderr_str();
assert!( !decoded.is_empty() );
assert!( decoded.contains( '\u{FFFD}' ) );
}
#[ test ]
fn captured_output_stdout_contains_empty_needle()
{
use the_module::CapturedOutput;
let out = CapturedOutput { exit_status : 0, stdout : b"hello".to_vec(), stderr : vec![] };
assert!( out.stdout_contains( "" ), "empty needle must always match (str::contains semantics)" );
let empty_out = CapturedOutput { exit_status : 0, stdout : vec![], stderr : vec![] };
assert!( empty_out.stdout_contains( "" ), "empty needle on empty stdout must also match" );
}
#[ test ]
fn captured_output_stderr_eq_exact_match()
{
use the_module::CapturedOutput;
let out = CapturedOutput
{
exit_status : 1,
stdout : vec![],
stderr : b"error\n".to_vec(),
};
assert!( out.stderr_eq( "error\n" ) );
assert!( !out.stderr_eq( "error" ) ); assert!( !out.stderr_eq( "other\n" ) ); }
#[ test ]
fn captured_output_assert_exit_ok_no_panic()
{
use the_module::CapturedOutput;
let out = CapturedOutput { exit_status : 0, stdout : vec![], stderr : vec![] };
out.assert_exit_ok(); }
#[ test ]
fn captured_output_assert_empty_no_panic()
{
use the_module::CapturedOutput;
let out = CapturedOutput { exit_status : 0, stdout : vec![], stderr : vec![] };
out.assert_stdout_empty(); out.assert_stderr_empty(); }
#[ test ]
fn captured_output_clone_is_independent()
{
use the_module::CapturedOutput;
let original = CapturedOutput { exit_status : 42, stdout : b"hi\n".to_vec(), stderr : vec![] };
let mut cloned = original.clone();
cloned.exit_status = 0;
cloned.stdout.clear();
assert_eq!( original.exit_status, 42 );
assert_eq!( original.stdout, b"hi\n" );
}
#[ test ]
fn run_options_default_sentinel_values()
{
use the_module::RunOptions;
let opts = RunOptions::default();
assert_eq!( opts.build_profile, "" );
assert_eq!( opts.cargo_path, "" );
assert_eq!( opts.edition, "" );
assert_eq!( opts.package_name, "" );
assert!( opts.target_dir.is_none() );
assert!( opts.timeout_ms.is_none() );
assert!( opts.features.is_empty() );
assert!( opts.env_vars.is_empty() );
assert!( opts.capture, "capture must default to true" );
assert!( opts.cleanup, "cleanup must default to true" );
}
#[ test ]
fn run_options_clone_is_independent()
{
use the_module::RunOptions;
let original = RunOptions { timeout_ms : Some( 5_000 ), capture : false, ..Default::default() };
let mut cloned = original.clone();
cloned.timeout_ms = None;
cloned.capture = true;
assert_eq!( original.timeout_ms, Some( 5_000 ) );
assert!( !original.capture );
}
#[ test ]
fn run_options_debug_formatting()
{
use the_module::RunOptions;
let opts = RunOptions::default();
let formatted = format!( "{opts:?}" );
assert!( !formatted.is_empty() );
assert!( formatted.contains( "RunOptions" ) );
}
#[ test ]
fn program_manifest_field_stored()
{
use the_module::program;
let toml = "[package]\nname = \"custom\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n";
let prog = program::Program::former()
.manifest( toml.to_string() )
.form();
assert_eq!( prog.manifest.as_deref(), Some( toml ) );
}
#[ test ]
fn program_manifest_defaults_to_none()
{
use the_module::program;
let prog = program::Program::former().form();
assert!( prog.manifest.is_none() );
}
#[ test ]
fn plan_with_run_options_stored()
{
use the_module::{ program, RunOptions };
let opts = RunOptions { timeout_ms : Some( 1_000 ), capture : false, ..Default::default() };
let plan = program::Plan::former()
.program()
.end()
.run_options( opts )
.form();
let stored = plan.run_options.expect( "run_options must be Some when explicitly set" );
assert_eq!( stored.timeout_ms, Some( 1_000 ) );
assert!( !stored.capture );
}
#[ test ]
fn plan_without_run_options_is_none()
{
use the_module::program;
let plan = program::Plan::former()
.program()
.end()
.form();
assert!( plan.run_options.is_none() );
}