From f3b049e8780ca4081bf34e43dcdc6577e9aba456 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 22 Mar 2022 13:36:38 +0100 Subject: [PATCH] commandtest: Use virTestCompareToFile() in checkoutput() In the commandtest there is checkoutput() function which checks the latest log of commandhelper (containing things like cmd line arguments, env vars, FDs, CWD, etc.) and compares that against expected output. Well, the way this function implements that is effectively by open coding virTestCompareToFile() except for the nice feature that the virTestCompareToFile() has: VIR_TEST_OUTPUT_REGENERATE. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tests/commandtest.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index 6d45ff196f..ffc4b24ef4 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -58,29 +58,18 @@ static int checkoutput(const char *testname) { int ret = -1; g_autofree char *expectname = NULL; - g_autofree char *expectlog = NULL; g_autofree char *actualname = NULL; g_autofree char *actuallog = NULL; expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname); actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir); - if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) { - fprintf(stderr, "cannot read %s\n", expectname); - goto cleanup; - } - if (virFileReadAll(actualname, 1024*64, &actuallog) < 0) { fprintf(stderr, "cannot read %s\n", actualname); goto cleanup; } - if (STRNEQ(expectlog, actuallog)) { - virTestDifference(stderr, expectlog, actuallog); - goto cleanup; - } - - ret = 0; + ret = virTestCompareToFile(actuallog, expectname); cleanup: if (actualname) @@ -1292,6 +1281,7 @@ mymain(void) * since we're about to reset 'environ' */ ignore_value(virTestGetDebug()); ignore_value(virTestGetVerbose()); + ignore_value(virTestGetRegenerate()); /* Make sure to not leak fd's */ virinitret = virInitialize(); -- 2.47.2