use std::process::Command;
#[test]
fn test_for_each_trivial_output_not_duplicated()
{
let output = Command::new( "cargo" )
.args( [ "run", "--example", "for_each_trivial", "--features", "enabled" ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute example" );
let stdout = String::from_utf8_lossy( &output.stdout );
let stderr = String::from_utf8_lossy( &output.stderr );
let debug_count = stdout.lines()
.chain( stderr.lines() )
.filter( | line | line.contains( "for_each_trivial.rs:" ) && line.contains( '=' ) )
.count();
assert_eq!(
debug_count,
3,
"Example should produce exactly 3 debug outputs, found {debug_count}\nStdout:\n{stdout}\nStderr:\n{stderr}"
);
}
#[test]
fn test_for_each_map_style_output_not_duplicated()
{
let output = Command::new( "cargo" )
.args( [ "run", "--example", "for_each_map_style_sample", "--features", "enabled" ] )
.current_dir( env!( "CARGO_MANIFEST_DIR" ) )
.output()
.expect( "Failed to execute example" );
let stdout = String::from_utf8_lossy( &output.stdout );
let stderr = String::from_utf8_lossy( &output.stderr );
let debug_count = stdout.lines()
.chain( stderr.lines() )
.filter( | line | line.contains( "for_each_map_style_sample.rs:" ) && line.contains( '=' ) )
.count();
assert_eq!(
debug_count,
3,
"Example should produce exactly 3 debug outputs, found {debug_count}\nStdout:\n{stdout}\nStderr:\n{stderr}"
);
}
#[test]
fn test_examples_have_proper_documentation()
{
let trivial_src = std::fs::read_to_string(
std::path::Path::new( env!( "CARGO_MANIFEST_DIR" ) )
.join( "examples" )
.join( "for_each_trivial.rs" )
).expect( "Failed to read for_each_trivial.rs" );
assert!(
!trivial_src.contains( "qqq:" ),
"for_each_trivial.rs should not contain unresolved TODO markers (qqq:)"
);
let map_style_src = std::fs::read_to_string(
std::path::Path::new( env!( "CARGO_MANIFEST_DIR" ) )
.join( "examples" )
.join( "for_each_map_style_sample.rs" )
).expect( "Failed to read for_each_map_style_sample.rs" );
assert!(
!map_style_src.contains( "qqq:" ),
"for_each_map_style_sample.rs should not contain unresolved TODO markers (qqq:)"
);
}