From 85ddd57db95774c987f3cf6219c7c14689e191ec Mon Sep 17 00:00:00 2001 From: Tom Huang Date: Sun, 17 Nov 2024 07:43:14 -0800 Subject: [PATCH] fix: improve test cases for mingw In the MinGW environment, the path separator is the forward slash. However, currently the test cases expect the backward slash, which causes test failures. In this patch, we improve the test cases for arg_filexxx API, so they expect forward slash and can pass the unit tests. --- tests/testargfile.c | 57 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/tests/testargfile.c b/tests/testargfile.c index ad457e4..cd42f30 100644 --- a/tests/testargfile.c +++ b/tests/testargfile.c @@ -710,7 +710,7 @@ void test_argfile_basic_032(CuTest* tc) { arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); } -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) void test_argfile_basic_033(CuTest* tc) { struct arg_file* a = arg_filen(NULL, NULL, "", 0, 3, "filename to test"); struct arg_end* end = arg_end(20); @@ -760,7 +760,57 @@ void test_argfile_basic_034(CuTest* tc) { arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); } -#endif /* #ifdef WIN32 */ +#else +void test_argfile_basic_033(CuTest* tc) { + struct arg_file* a = arg_filen(NULL, NULL, "", 0, 3, "filename to test"); + struct arg_end* end = arg_end(20); + void* argtable[] = {a, end}; + int nerrors; + + char* argv[] = {"program", "/test folder/", "/test folder2", NULL}; + int argc = sizeof(argv) / sizeof(char*) - 1; + + CuAssertTrue(tc, arg_nullcheck(argtable) == 0); + nerrors = arg_parse(argc, argv, argtable); + + CuAssertTrue(tc, nerrors == 0); + CuAssertTrue(tc, a->count == 2); + CuAssertStrEquals(tc, a->filename[0], "/test folder/"); + CuAssertStrEquals(tc, a->basename[0], ""); + CuAssertStrEquals(tc, a->extension[0], ""); + CuAssertStrEquals(tc, a->filename[1], "/test folder2"); + CuAssertStrEquals(tc, a->basename[1], "test folder2"); + CuAssertStrEquals(tc, a->extension[1], ""); + + arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); +} + +void test_argfile_basic_034(CuTest* tc) { + struct arg_file* a = arg_filen(NULL, NULL, "", 1, 1, "path a"); + struct arg_file* b = arg_filen(NULL, NULL, "", 1, 1, "path b"); + struct arg_end* end = arg_end(20); + void* argtable[] = {a, b, end}; + int nerrors; + + char* argv[] = {"program", "/test folder/", "/test folder2", NULL}; + int argc = sizeof(argv) / sizeof(char*) - 1; + + CuAssertTrue(tc, arg_nullcheck(argtable) == 0); + nerrors = arg_parse(argc, argv, argtable); + + CuAssertTrue(tc, nerrors == 0); + CuAssertTrue(tc, a->count == 1); + CuAssertStrEquals(tc, a->filename[0], "/test folder/"); + CuAssertStrEquals(tc, a->basename[0], ""); + CuAssertStrEquals(tc, a->extension[0], ""); + CuAssertTrue(tc, b->count == 1); + CuAssertStrEquals(tc, b->filename[0], "/test folder2"); + CuAssertStrEquals(tc, b->basename[0], "test folder2"); + CuAssertStrEquals(tc, b->extension[0], ""); + + arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); +} +#endif /* #if defined(WIN32) && !defined(__MINGW32__) */ CuSuite* get_argfile_testsuite() { CuSuite* suite = CuSuiteNew(); @@ -796,11 +846,8 @@ CuSuite* get_argfile_testsuite() { SUITE_ADD_TEST(suite, test_argfile_basic_030); SUITE_ADD_TEST(suite, test_argfile_basic_031); SUITE_ADD_TEST(suite, test_argfile_basic_032); -#ifdef WIN32 SUITE_ADD_TEST(suite, test_argfile_basic_033); SUITE_ADD_TEST(suite, test_argfile_basic_034); -#endif /* #ifdef WIN32 */ - return suite; }