feat: add human-readable output flag
CI / lint (pull_request) Successful in 12s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 36s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 34s
CI / lint (pull_request) Successful in 12s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 36s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 34s
This commit is contained in:
@@ -26,6 +26,12 @@ def setup_test_data():
|
||||
|
||||
|
||||
class TestDryRun:
|
||||
def test_human_readable_dry_run(self):
|
||||
result, dur = run_client(SOURCE_DIR, DEST_DIR, flags=["-h", "--dry-run"])
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
assert "Total:" in result.stdout
|
||||
assert "KB" in result.stdout
|
||||
|
||||
def test_dry_run(self):
|
||||
clean_dir(DEST_DIR)
|
||||
result, dur = run_client(
|
||||
@@ -263,6 +269,17 @@ class TestProgress:
|
||||
assert "Sent " in output and "MB" in output, "--progress produced no stable byte marker"
|
||||
assert "Done." in output, "--progress did not report completion"
|
||||
|
||||
def test_human_readable_stats(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
result, dur = run_client(
|
||||
SOURCE_DIR, DEST_DIR,
|
||||
flags=["-h", "--stats"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
assert "Stats:" in result.stderr
|
||||
assert "KB" in result.stderr
|
||||
|
||||
|
||||
class TestBandwidthLimit:
|
||||
def test_bwlimit_runs(self, shared_server):
|
||||
|
||||
+15
-2
@@ -280,8 +280,6 @@ static void test_parse_args_rejects_unimplemented_options() {
|
||||
"--info",
|
||||
"--debug",
|
||||
"--list-only",
|
||||
"-h",
|
||||
"--human-readable",
|
||||
"-u",
|
||||
"--update",
|
||||
"--append",
|
||||
@@ -323,6 +321,20 @@ static void test_parse_args_rejects_unimplemented_options() {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_parse_args_human_readable() {
|
||||
static const char* const options[] = {"-h", "--human-readable"};
|
||||
for (size_t i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", (char*)options[i], "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
|
||||
EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), 0);
|
||||
EXPECT_TRUE(cfg->human_readable);
|
||||
config_delete(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test parse_args with --archive flag */
|
||||
static void test_parse_args_archive() {
|
||||
Config* cfg = config_create();
|
||||
@@ -359,5 +371,6 @@ void test_client_cli() {
|
||||
test_parse_args_valid_compression_level();
|
||||
test_parse_args_unknown_option();
|
||||
test_parse_args_rejects_unimplemented_options();
|
||||
test_parse_args_human_readable();
|
||||
test_parse_args_archive();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,15 @@
|
||||
#include <string.h>
|
||||
|
||||
void test_shared_utils() {
|
||||
char formatted[32];
|
||||
EXPECT_TRUE(format_human_bytes(0, formatted, sizeof(formatted)));
|
||||
EXPECT_EQ_STR(formatted, "0 B");
|
||||
EXPECT_TRUE(format_human_bytes(1024, formatted, sizeof(formatted)));
|
||||
EXPECT_EQ_STR(formatted, "1.0 KB");
|
||||
EXPECT_TRUE(format_human_bytes(1536 * 1024, formatted, sizeof(formatted)));
|
||||
EXPECT_EQ_STR(formatted, "1.5 MB");
|
||||
EXPECT_FALSE(format_human_bytes(1024, formatted, 4));
|
||||
|
||||
// Test str_dup
|
||||
const char* dup_null = str_dup(NULL);
|
||||
EXPECT_NULL(dup_null);
|
||||
|
||||
Reference in New Issue
Block a user