Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/msys2-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: git config --global core.autocrlf input

- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Set up MSYS2
uses: msys2/setup-msys2@v2
Expand All @@ -45,9 +45,7 @@ jobs:
run: make -j"$(nproc)"

- name: Run internal self-tests
run: |
./CUnit/Sources/Test/test_cunit | tee test_cunit.log
grep -q "Failures: 0" test_cunit.log
run: make check

- name: Install
run: make install
Expand Down
27 changes: 13 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Verify tag matches VERSION
id: verify
Expand Down Expand Up @@ -66,8 +66,8 @@ jobs:
exit 1
fi

if ! grep -Fq 'm4_esyscmd_s([cat VERSION])' configure.in; then
echo "configure.in does not read VERSION for AC_INIT" >&2
if ! grep -Fq 'm4_esyscmd_s([cat VERSION])' configure.ac; then
echo "configure.ac does not read VERSION for AC_INIT" >&2
exit 1
fi

Expand All @@ -84,7 +84,7 @@ jobs:

steps:
- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install build dependencies
run: |
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
tar -tzf "${DIST_FILE}.tar.gz" | grep -Fx "${DIST_FILE}/Examples/ExampleTests.h"

- name: Upload source dist
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: cunit-source-dist
path: ${{ needs.verify-version.outputs.dist_file }}.tar.gz
Expand All @@ -136,7 +136,7 @@ jobs:
run: git config --global core.autocrlf input

- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Set up MSYS2
uses: msys2/setup-msys2@v2
Expand All @@ -149,7 +149,7 @@ jobs:
git

- name: Download source dist for PKGBUILD
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
name: cunit-source-dist
path: packaging/msys2
Expand All @@ -159,7 +159,7 @@ jobs:
run: MINGW_ARCH=ucrt64 makepkg-mingw -sCLf --noconfirm

- name: Upload release assets
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: cunit-release-assets
path: |
Expand All @@ -180,7 +180,7 @@ jobs:
run: dnf -y install gcc make diffutils findutils tar gzip

- name: Download source dist
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
name: cunit-source-dist
path: .
Expand All @@ -198,8 +198,7 @@ jobs:
--enable-examples \
--enable-test
make -j"$(nproc)"
./CUnit/Sources/Test/test_cunit | tee test_cunit.log
grep -q "Failures: 0" test_cunit.log
make check

test-package:
name: Test installed release package (UCRT64)
Expand All @@ -222,7 +221,7 @@ jobs:
mingw-w64-ucrt-x86_64-pkgconf

- name: Download release assets
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
name: cunit-release-assets
path: release-assets
Expand Down Expand Up @@ -264,12 +263,12 @@ jobs:

steps:
- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Download release assets
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
name: cunit-release-assets
path: release-assets
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install build dependencies
run: |
Expand All @@ -42,9 +42,7 @@ jobs:
run: make -j"$(nproc)"

- name: Run internal self-tests
run: |
./CUnit/Sources/Test/test_cunit | tee test_cunit.log
grep -q "Failures: 0" test_cunit.log
run: make check

- name: Install
run: make install
Expand All @@ -59,7 +57,7 @@ jobs:

steps:
- name: Check out source
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install build dependencies
run: |
Expand All @@ -84,9 +82,7 @@ jobs:
run: make -j"$(nproc)"

- name: Run internal self-tests
run: |
./CUnit/Sources/Test/test_cunit | tee test_cunit.log
grep -q "Failures: 0" test_cunit.log
run: make check

- name: Generate coverage report
run: |
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
m4
test-driver
**/Makefile.in
aclocal.m4
autom4te.cache/
Expand Down Expand Up @@ -30,3 +32,7 @@ CUnit/Headers/CUnit.h
CUnit*Dump.xml
stamp-h1
CUnit/Sources/Test/test_cunit
CUnit/Sources/Test/test-suite.log
CUnit/Sources/Test/test_cunit.log
CUnit/Sources/Test/test_cunit.trs
cunit-*.tar.gz
70 changes: 56 additions & 14 deletions CUnit/Sources/Console/Console.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <limits.h>
#include <string.h>

#include "CUnit.h"
Expand All @@ -80,6 +81,17 @@ static CU_pSuite f_pRunningSuite = NULL;
/** Common width measurements for output formatting. */
static size_t f_yes_width = 0;
static size_t f_no_width = 0;
/* printf width and precision arguments are typed as int. */
static int display_width(size_t width)
{
assert(width <= INT_MAX);
return (int)width;
}

static size_t max_size_t(size_t a, size_t b)
{
return (a >= b) ? a : b;
}

/*=================================================================
* Static function forward declarations
Expand All @@ -104,6 +116,23 @@ static CU_ErrorCode select_suite(CU_pTestRegistry pRegistry, CU_pSuite* ppSuite)
static void list_suites(CU_pTestRegistry pRegistry);
static void list_tests(CU_pSuite pSuite);
static void show_failures(void);
static int read_line(char* buffer, size_t size);

/*=================================================================
* Private helper functions
*=================================================================*/
static int read_line(char* buffer, size_t size)
{
if (NULL == fgets(buffer, (int)size, stdin)) {
if (size > 0) {
buffer[0] = '\0';
}
clearerr(stdin);
return 0;
}

return 1;
}

/*=================================================================
* Public Interface functions
Expand Down Expand Up @@ -164,7 +193,10 @@ static void console_registry_level_run(CU_pTestRegistry pRegistry)
_("(R)un (S)elect (L)ist (A)ctivate (F)ailures (O)ptions (H)elp (Q)uit"),
_("Enter command: "));
chChoice = toupper(getchar());
fgets(szTemp, 256, stdin); /* flush any chars out of the read buffer */
if (!read_line(szTemp, sizeof(szTemp))) {
eStatus = CU_STATUS_STOP;
continue;
}

if (chChoice == _("R")[0]) {
console_run_all_tests(pRegistry);
Expand Down Expand Up @@ -243,7 +275,10 @@ static CU_STATUS console_suite_level_run(CU_pSuite pSuite)
_("(R)un (S)elect (L)ist (A)ctivate (F)ailures (U)p (O)ptions (H)elp (Q)uit"),
_("Enter command: "));
chChoice = toupper(getchar());
fgets(szTemp, 256, stdin); /* flush any chars out of the read buffer */
if (!read_line(szTemp, sizeof(szTemp))) {
eStatus = CU_STATUS_STOP;
continue;
}

if (chChoice == _("R")[0]) {
console_run_suite(pSuite);
Expand Down Expand Up @@ -322,7 +357,10 @@ static CU_STATUS console_set_options_run(void)
fprintf(stdout, "%s",
_("Enter number of option to change : "));
chChoice = getchar();
fgets(szTemp, 256, stdin); /* flush any chars out of the read buffer */
if (!read_line(szTemp, sizeof(szTemp))) {
eStatus = CU_STATUS_MOVE_UP;
continue;
}

switch (tolower(chChoice)) {
case '1':
Expand Down Expand Up @@ -420,7 +458,9 @@ static CU_ErrorCode select_test(CU_pSuite pSuite, CU_pTest* ppTest)
fprintf(stdout, "\n");
fprintf(stdout, _("Enter number of test to select (1-%u) : "),
pSuite->uiNumberOfTests);
fgets(buffer, 100, stdin);
if (!read_line(buffer, sizeof(buffer))) {
return CUE_NOTEST;
}

*ppTest = CU_get_test_by_index(atol(buffer), pSuite);
}
Expand Down Expand Up @@ -459,7 +499,9 @@ static CU_ErrorCode select_suite(CU_pTestRegistry pRegistry, CU_pSuite* ppSuite)
fprintf(stdout, "\n");
fprintf(stdout, _("Enter number of suite to select (1-%u) : "),
pRegistry->uiNumberOfSuites);
fgets(buffer, 100, stdin);
if (!read_line(buffer, sizeof(buffer))) {
return CUE_NOSUITE;
}

*ppSuite = CU_get_suite_by_index(atol(buffer), pRegistry);
}
Expand All @@ -476,7 +518,7 @@ static void list_suites(CU_pTestRegistry pRegistry)
{
CU_pSuite pCurSuite = NULL;
int i;
static size_t width[6];
static int width[6];

if (NULL == pRegistry) {
pRegistry = CU_get_registry();
Expand All @@ -492,12 +534,12 @@ static void list_suites(CU_pTestRegistry pRegistry)

/* only need to calculate formatting widths once */
if (0 == width[0]) {
width[0] = CU_number_width(pRegistry->uiNumberOfSuites) + 1;
width[0] = display_width(CU_number_width(pRegistry->uiNumberOfSuites) + 1);
width[1] = 34;
width[2] = CU_MAX(strlen(_("Init?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[3] = CU_MAX(strlen(_("Cleanup?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[4] = CU_MAX(strlen(_("#Tests")), CU_number_width(pRegistry->uiNumberOfTests) + 1) + 1;
width[5] = CU_MAX(strlen(_("Active?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[2] = display_width(max_size_t(strlen(_("Init?")), max_size_t(f_yes_width, f_no_width)) + 1);
width[3] = display_width(max_size_t(strlen(_("Cleanup?")), max_size_t(f_yes_width, f_no_width)) + 1);
width[4] = display_width(CU_MAX(strlen(_("#Tests")), CU_number_width(pRegistry->uiNumberOfTests) + 1) + 1);
width[5] = display_width(max_size_t(strlen(_("Active?")), max_size_t(f_yes_width, f_no_width)) + 1);
}

fprintf(stdout, "\n%s", _("--------------------- Registered Suites -----------------------------"));
Expand Down Expand Up @@ -533,7 +575,7 @@ static void list_tests(CU_pSuite pSuite)
{
CU_pTest pCurTest = NULL;
unsigned int uiCount;
static size_t width[3];
static int width[3];

assert(NULL != pSuite);
assert(NULL != pSuite->pName);
Expand All @@ -548,10 +590,10 @@ static void list_tests(CU_pSuite pSuite)
assert(NULL != pSuite->pTest);

/* only number of tests can change between calls */
width[0] = CU_number_width(pSuite->uiNumberOfTests) + 1;
width[0] = display_width(CU_number_width(pSuite->uiNumberOfTests) + 1);
if (0 == width[1]) {
width[1] = 34;
width[2] = CU_MAX(strlen(_("Active?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[2] = display_width(max_size_t(strlen(_("Active?")), max_size_t(f_yes_width, f_no_width)) + 1);
}

fprintf(stdout, "\n%s",
Expand Down
2 changes: 1 addition & 1 deletion CUnit/Sources/Framework/MyMem.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void CU_dump_memory_usage(const char* szFilename)
pTempEvent = pTempNode->pFirstEvent;
while (NULL != pTempEvent) {
fprintf(pFile, "\n <MD_EVENT_RECORD>");
fprintf(pFile, "\n <MD_SIZE> %u </MD_SIZE>", pTempEvent->Size);
fprintf(pFile, "\n <MD_SIZE> %zu </MD_SIZE>", pTempEvent->Size);
fprintf(pFile, "\n <MD_ALLOC_FILE> %s </MD_ALLOC_FILE>", pTempEvent->AllocFilename);
fprintf(pFile, "\n <MD_ALLOC_LINE> %u </MD_ALLOC_LINE>", pTempEvent->AllocLine);
fprintf(pFile, "\n <MD_DEALLOC_FILE> %s </MD_DEALLOC_FILE>", pTempEvent->DeallocFilename);
Expand Down
30 changes: 10 additions & 20 deletions CUnit/Sources/Framework/TestDB.c
Original file line number Diff line number Diff line change
Expand Up @@ -1405,16 +1405,6 @@ static void test_get_suite_functions(void)
CU_pSuite pSuite3 = NULL;
CU_pSuite pSuite4 = NULL;
CU_pSuite pSuite5 = NULL;
CU_pTest pTest1 = NULL;
CU_pTest pTest2 = NULL;
CU_pTest pTest3 = NULL;
CU_pTest pTest4 = NULL;
CU_pTest pTest5 = NULL;
CU_pTest pTest6 = NULL;
CU_pTest pTest7 = NULL;
CU_pTest pTest8 = NULL;
CU_pTest pTest9 = NULL;
CU_pTest pTest10 = NULL;

/* error condition - registry not initialized */
CU_cleanup_registry();
Expand All @@ -1438,19 +1428,19 @@ static void test_get_suite_functions(void)
/* register some suites and tests */
CU_initialize_registry();
pSuite1 = CU_add_suite("suite1", NULL, NULL);
pTest1 = CU_add_test(pSuite1, "test1", test_succeed);
pTest2 = CU_add_test(pSuite1, "test2", test_fail);
pTest3 = CU_add_test(pSuite1, "test1", test_succeed); /* duplicate test name */
pTest4 = CU_add_test(pSuite1, "test4", test_fail);
pTest5 = CU_add_test(pSuite1, "test1", test_succeed); /* duplicate test name */
CU_add_test(pSuite1, "test1", test_succeed);
CU_add_test(pSuite1, "test2", test_fail);
CU_add_test(pSuite1, "test1", test_succeed); /* duplicate test name */
CU_add_test(pSuite1, "test4", test_fail);
CU_add_test(pSuite1, "test1", test_succeed); /* duplicate test name */
pSuite2 = CU_add_suite("suite2", suite_fail, NULL);
pTest6 = CU_add_test(pSuite2, "test6", test_succeed);
pTest7 = CU_add_test(pSuite2, "test7", test_succeed);
CU_add_test(pSuite2, "test6", test_succeed);
CU_add_test(pSuite2, "test7", test_succeed);
pSuite3 = CU_add_suite("suite1", NULL, NULL); /* duplicate suite name */
pTest8 = CU_add_test(pSuite3, "test8", test_fail);
pTest9 = CU_add_test(pSuite3, "test9", test_succeed);
CU_add_test(pSuite3, "test8", test_fail);
CU_add_test(pSuite3, "test9", test_succeed);
pSuite4 = CU_add_suite("suite4", NULL, suite_fail);
pTest10 = CU_add_test(pSuite4, "test10", test_succeed);
CU_add_test(pSuite4, "test10", test_succeed);

/* error condition - invalid parameters */

Expand Down
Loading
Loading