use tempfile::TempDir;
use crate::subprocess_helpers::{ assert_exit, run_clm, run_clm_with_env, stdout, write_settings };
#[ test ]
fn format_ec11_status_format_json_object()
{
let out = run_clm( &[ ".status", "format::json" ] );
assert_exit( &out, 0 );
let text = stdout( &out );
assert!( text.trim_start().starts_with( '{' ), "status format::json must start with {{: {text}" );
}
#[ test ]
fn format_ec12_version_show_format_json_has_version_key()
{
let out = run_clm( &[ ".version.show", "format::json" ] );
if out.status.code() == Some( 0 )
{
let text = stdout( &out );
assert!( text.contains( "\"version\"" ), "version.show json must have 'version' key: {text}" );
assert!( text.trim_start().starts_with( '{' ), "must be a JSON object: {text}" );
}
}
#[ test ]
fn format_ec13_version_list_format_json_array()
{
let out = run_clm( &[ ".version.list", "format::json" ] );
assert_exit( &out, 0 );
let text = stdout( &out );
assert!( text.trim_start().starts_with( '[' ), "version.list format::json must start with [: {text}" );
}
#[ test ]
fn format_ec14_processes_format_json_has_processes_key()
{
let out = run_clm( &[ ".processes", "format::json" ] );
assert_exit( &out, 0 );
let text = stdout( &out );
assert!( text.contains( "\"processes\"" ), "processes json must have 'processes' key: {text}" );
}
#[ test ]
fn format_ec15_settings_show_format_json_object()
{
let dir = TempDir::new().unwrap();
let home = dir.path().to_str().unwrap();
write_settings( dir.path(), &[ ( "myKey", "myVal" ) ] );
let out = run_clm_with_env(
&[ ".settings.show", "format::json" ],
&[ ( "HOME", home ) ],
);
assert_exit( &out, 0 );
let text = stdout( &out );
assert!( text.trim_start().starts_with( '{' ), "settings.show json must be an object: {text}" );
assert!( text.contains( "myKey" ), "json must contain the key: {text}" );
}
#[ test ]
fn format_ec16_settings_get_format_json_has_key_value()
{
let dir = TempDir::new().unwrap();
let home = dir.path().to_str().unwrap();
write_settings( dir.path(), &[ ( "myKey", "myVal" ) ] );
let out = run_clm_with_env(
&[ ".settings.get", "key::myKey", "format::json" ],
&[ ( "HOME", home ) ],
);
assert_exit( &out, 0 );
let text = stdout( &out );
assert!( text.contains( "\"key\"" ) || text.contains( "\"value\"" ),
"settings.get json must have key/value fields: {text}" );
}
#[ test ]
fn format_ec17_history_format_json_fields()
{
let out = run_clm( &[ ".version.history", "format::json", "count::3" ] );
if out.status.code() == Some( 0 )
{
let text = stdout( &out );
assert!( text.trim_start().starts_with( '[' ), "history json must be an array: {text}" );
assert!( text.contains( "\"version\"" ), "history json entries must have 'version' field: {text}" );
}
}
#[ test ]
fn format_ec18_history_format_xml_exits_1()
{
let out = run_clm( &[ ".version.history", "format::xml" ] );
assert_exit( &out, 1 );
}
#[ test ]
fn format_ec19_history_format_json_uppercase_exits_1()
{
let out = run_clm( &[ ".version.history", "format::JSON" ] );
assert_exit( &out, 1 );
}