mod common;
use tempfile::TempDir;
fn stdout( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stdout ).into_owned()
}
fn stderr( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stderr ).into_owned()
}
fn assert_exit( out : &std::process::Output, code : i32 )
{
assert_eq!(
out.status.code().unwrap_or( -1 ),
code,
"expected exit {code}, got {:?}; stderr: {}",
out.status.code(),
stderr( out )
);
}
#[ test ]
fn ec_1_count_1_integer_only()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-cnt", "sess", 2 );
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "count::1" )
.output()
.unwrap();
assert_exit( &out, 0 );
let output = stdout( &out );
assert!(
!output.is_empty(),
"EC-1: count::1 must produce output; got empty stdout"
);
}
#[ test ]
fn ec_2_count_0_full_list_output()
{
let root = TempDir::new().unwrap();
common::write_test_session( root.path(), "proj-cnt2", "sess", 2 );
let out_count0 = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "count::0" )
.output()
.unwrap();
let out_default = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.output()
.unwrap();
assert_exit( &out_count0, 0 );
assert_exit( &out_default, 0 );
assert_eq!(
stdout( &out_count0 ),
stdout( &out_default ),
"EC-2: count::0 must produce identical output to no-count list"
);
}
#[ test ]
fn ec_3_count_2_rejected()
{
let out = common::clg_cmd()
.arg( ".list" )
.arg( "count::2" )
.output()
.unwrap();
assert_exit( &out, 1 );
let err = stderr( &out );
assert!(
!err.is_empty(),
"EC-3: expected non-empty error for count::2 (out-of-range boolean); got empty stderr"
);
}
#[ test ]
fn ec_4_count_yes_accepted()
{
let out = common::clg_cmd()
.arg( ".list" )
.arg( "count::yes" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_5_count_1_empty_storage_outputs_zero()
{
let root = TempDir::new().unwrap();
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "count::1" )
.output()
.unwrap();
assert_exit( &out, 0 );
}
#[ test ]
fn ec_6_count_1_always_exits_0()
{
let root = TempDir::new().unwrap();
let out = common::clg_cmd()
.env( "CLAUDE_STORAGE_ROOT", root.path() )
.arg( ".list" )
.arg( "count::1" )
.output()
.unwrap();
assert_exit( &out, 0 );
}