Skip to content

Commit

Permalink
fix: improve test cases for mingw
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomghuang committed Nov 17, 2024
1 parent 0c0932d commit 85ddd57
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions tests/testargfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<file>", 0, 3, "filename to test");
struct arg_end* end = arg_end(20);
Expand Down Expand Up @@ -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, "<file>", 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, "<file>", 1, 1, "path a");
struct arg_file* b = arg_filen(NULL, NULL, "<file>", 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();
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 85ddd57

Please sign in to comment.