Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
51d03d3
Add macOS CI
mathomp4 Aug 24, 2023
f80372d
Explicit LEX and YACC
mathomp4 Aug 24, 2023
a7f8206
Allow override of LEX and YACC; merge changes from macos-ci branch
mathomp4 Aug 30, 2023
582f1fa
Turn off whitebox
mathomp4 Aug 30, 2023
5262bce
Use GNU grep on macos
mathomp4 Aug 30, 2023
b292c99
macos runners have git libunistring pcre2 and ncurses by default
mathomp4 Aug 30, 2023
2e1ac9c
Add gnu-sed
mathomp4 Aug 30, 2023
efa6e2d
Add findutils for xargs
mathomp4 Aug 30, 2023
37c85d4
Add LC_ALL
mathomp4 Aug 30, 2023
4457fea
Remove LC_ALL as more tests crashed with it
mathomp4 Aug 30, 2023
282a537
Update to checkout v4
mathomp4 Nov 25, 2023
c637469
move to branch_coverage to avoid warning
mathomp4 Nov 25, 2023
b52709b
Ignore unused error
mathomp4 Nov 25, 2023
153b570
Try and handle test 111
mathomp4 Nov 25, 2023
b51b247
Try and handle multiple coveralls
mathomp4 Nov 25, 2023
a9d968d
.gitignore add VS Code and JetBrains CLion files
chorpler Nov 25, 2023
894e3cb
Change bx_fprintf to a function pointer to enable unit testing on MacOS
chorpler Nov 25, 2023
ea541d0
`setup_mocks()` should set function pointer `bx_fprintf` to point to …
chorpler Nov 25, 2023
8b59fa6
Update Makefile, src/Makefile, and utest/Makefile to support MacOS un…
chorpler Nov 25, 2023
ce89dec
tools.h - change `set_bx_fprintf()` function declaration to match ren…
chorpler Nov 26, 2023
efe9fc2
Enable white-box tests on macOS
mathomp4 Nov 26, 2023
0dbab43
Add flex and bison to env
mathomp4 Nov 26, 2023
e66d12b
Remove ignore errors
mathomp4 Nov 26, 2023
30a46c0
Update function name to be wrapped in unit testing `Makefile`
chorpler Nov 27, 2023
c874cf1
use defines
mathomp4 Nov 27, 2023
b80c0c4
Removed linker `--wrap` option so unit tests run on macOS
chorpler Nov 28, 2023
f1bda75
Fix some problems with LEX and YACC defaults on Linux
tsjensen Dec 1, 2023
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
49 changes: 48 additions & 1 deletion .github/workflows/boxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: add-packages
run: |
Expand All @@ -45,3 +45,50 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: out/lcov-total.info
format: lcov
flag-name: run-linux
parallel: true

build-macos:
runs-on: macos-latest
env:
BX_LEX: /usr/local/opt/flex/bin/flex
BX_YACC: /usr/local/opt/bison/bin/bison
steps:
- uses: actions/checkout@v4

# We need to use GNU grep, sed, and xargs on macOS
- name: add-packages
run: |
brew install flex bison diffutils lcov cmocka grep gnu-sed findutils
echo '/usr/local/opt/grep/libexec/gnubin' >> $GITHUB_PATH
echo '/usr/local/opt/gnu-sed/libexec/gnubin' >> $GITHUB_PATH
echo '/usr/local/opt/findutils/libexec/gnubin' >> $GITHUB_PATH

- name: make cov
run: make cov

- name: Run white-box tests
run: make utest

- name: Run black-box tests
run: make covtest

- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: out/lcov-total.info
format: lcov
flag-name: run-macos
parallel: true

finish:
needs: [build, build-macos]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
carryforward: "run-linux,run-macos"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
.cproject
.project
/.idea/
/.history/
/coverage/
/cmake-build-debug/

Expand All @@ -40,6 +41,7 @@
/datagen/
/build/
CMakeUserPresets.json
*.swp

# Legacy locations of generated files (no longer in use)
/src/boxes
Expand All @@ -59,5 +61,8 @@ CMakeUserPresets.json
/boxes.portable.*.nupkg
*.nupkg.zip

# MacOS
.DS_Store

# Misc
/vs
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ DOC_FILES = doc/boxes.1 doc/boxes.el
PKG_NAME = boxes-$(BVERSION)
OUT_DIR = out

# Set some defaults for BX_LEX and BX_YACC but allow env variables to override them.
BX_LEX ?= flex
BX_YACC ?= bison

PCRE2_VERSION = 10.40
PCRE2_DIR = vendor/pcre2-$(PCRE2_VERSION)
LIBUNISTRING_VERSION = 1.0
Expand All @@ -44,7 +48,7 @@ WIN_CMOCKA_DIR = vendor/cmocka-$(WIN_CMOCKA_VERSION)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

build cov debug: infomsg replaceinfos
$(MAKE) -C src BOXES_PLATFORM=unix LEX=flex YACC=bison $@
$(MAKE) -C src BOXES_PLATFORM=unix LEX=$(BX_LEX) YACC=$(BX_YACC) $@

win32: infomsg replaceinfos
$(MAKE) -C src BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(PCRE2_DIR)/src LDFLAGS=-L../$(PCRE2_DIR)/.libs \
Expand Down Expand Up @@ -124,8 +128,8 @@ $(LIBNCURSES_DIR)/lib/libncurses.a: vendor/libncurses-$(LIBNCURSES_VERSION).tar.
cd $(LIBNCURSES_DIR) ; ./configure --enable-static ; $(MAKE)

static: infomsg replaceinfos $(LIBUNISTRING_DIR)/lib/.libs/libunistring.a $(PCRE2_DIR)/.libs/libpcre2-32.a $(LIBNCURSES_DIR)/lib/libncurses.a
$(MAKE) -C src BOXES_PLATFORM=static LEX=flex YACC=bison LIBUNISTRING_DIR=$(LIBUNISTRING_DIR) \
PCRE2_DIR=$(PCRE2_DIR) LIBNCURSES_DIR=$(LIBNCURSES_DIR) LIBNCURSES_WIN_INCLUDE=$(LIBNCURSES_WIN_INCLUDE) $@
$(MAKE) -C src BOXES_PLATFORM=static LEX=$(BX_LEX) YACC=$(BX_YACC) LIBUNISTRING_DIR=$(LIBUNISTRING_DIR) \
PCRE2_DIR=$(PCRE2_DIR) LIBNCURSES_DIR=$(LIBNCURSES_DIR) LIBNCURSES_WIN_INCLUDE=$(LIBNCURSES_WIN_INCLUDE) $@


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ flags_:
exit 1

parser.c parser.h: parser.y lex.yy.h | check_dir
$(YACC) --warnings=all --verbose --defines=parser.h --output=parser.c $<
$(YACC) -Wall --verbose --defines=parser.h -o parser.c $<

lex.yy.c lex.yy.h: lexer.l | check_dir
$(LEX) --header-file=lex.yy.h $<
Expand Down
15 changes: 14 additions & 1 deletion src/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
static pcre2_code *pattern_ascii_id = NULL;
static pcre2_code *pattern_ascii_id_strict = NULL;

/**
* Initialize the `bx_fprintf` function pointer to point to the original
* `bx_fprintf` function, now renamed `bx_fprintf_original`. During unit
* tests, this will be replaced with `__wrap_bx_fprintf`, which stores
* the result that would have been printed so the output can be validated.
* This is necessary for unit testing and CI to work with MacOS.
*/
bx_fprintf_t bx_fprintf = bx_fprintf_original;


static pcre2_code *get_pattern_ascii_id(int strict)
{
Expand Down Expand Up @@ -849,7 +858,7 @@ char *bx_strndup(const char *s, size_t n)



void bx_fprintf(FILE *stream, const char *format, ...)
void bx_fprintf_original(FILE *stream, const char *format, ...)
{
va_list va;
va_start(va, format);
Expand All @@ -858,6 +867,10 @@ void bx_fprintf(FILE *stream, const char *format, ...)
}


void set_bx_fprintf(bx_fprintf_t bx_fprintf_function) {
bx_fprintf = bx_fprintf_function;
}


FILE *bx_fopens(bxstr_t *pathname, char *mode)
{
Expand Down
21 changes: 19 additions & 2 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
}


/**
* Define type for a function pointer to specify which `bx_fprintf` function
* will be called. This enables unit testing on MacOS, since Apple's `ld`
* linker does not support the `--wrap` flag that GNU `ld` does.
*/
typedef void (*bx_fprintf_t)(FILE *stream, const char *format, ...);

/**
* Declare function pointer to be changed when running unit tests
*/
extern bx_fprintf_t bx_fprintf;

int empty_line(const line_t *line);


Expand Down Expand Up @@ -173,7 +185,7 @@ int tag_is_valid(char *tag);

/**
* Duplicate at most `n` bytes from the given string `s`. Memory for the new string is obtained with `malloc()`, and
* can be freed with `free()`. A terminating null byte is added. We include this implementation because the libc's
* can be freed with `free()`. A terminating null byte is added. We include this implementation because the libc's
* `strndup()` is not consistently available across all platforms.
* @param s a string
* @param n maximum number of characters to copy (excluding the null byte)
Expand All @@ -187,8 +199,13 @@ char *bx_strndup(const char *s, size_t n);
* @param stream Where to print, for example `stderr`
* @param format the format string, followed by the arguments of the format string
*/
void bx_fprintf(FILE *stream, const char *format, ...);
void bx_fprintf_original(FILE *stream, const char *format, ...);


/**
* Set the bx_fprintf_ptr function pointer to point to a specific function
*/
void set_bx_fprintf(bx_fprintf_t bx_fprintf_function);

/**
* Determine if the given string is an "ASCII ID", which means:
Expand Down
21 changes: 16 additions & 5 deletions test/testrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,23 @@ function execute_suite()
local countExecuted=0
local countFailed=0
local tc

# Note we are getting an encoding error with test 111 which is
# unique and runs under ISO_8859-15. But this only happens on macOS.
# So, if we run test 111 on macOS, we should run with LC_ALL=C
for tc in *.txt; do
if [ ${opt_coverage} == true ]; then
$0 --coverage "${tc}"
if [[ $(uname) == "Darwin" ]] && [[ ${tc} == "111"* ]]; then
LC_ALL=C $0 --coverage "${tc}"
else
$0 --coverage "${tc}"
fi
else
$0 "${tc}"
if [[ $(uname) == "Darwin" ]] && [[ ${tc} == "111"* ]]; then
LC_ALL=C $0 "${tc}"
else
$0 "${tc}"
fi
fi
if [ $? -ne 0 ]; then
overallResult=1
Expand All @@ -140,20 +152,19 @@ function measure_coverage()
mkdir -p "${testResultsDir}"
cp ${OUT_DIR}/*.gc* "${testResultsDir}"
lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc lcov_branch_coverage=1 \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \
--output-file "${testResultsDir}/coverage.info"
echo -n " Coverage: "
lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
fi
}


function consolidate_coverage()
{
echo -e "\nConsolidating test coverage ..."
pushd ${OUT_DIR}/test-results || exit 1
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
lcov --rc lcov_branch_coverage=1 --exclude '*/lex.yy.c' --exclude '*/parser.c' \
lcov --rc branch_coverage=1 --exclude '*/lex.yy.c' --exclude '*/parser.c' \
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
popd || exit 1
echo ""
Expand Down
5 changes: 2 additions & 3 deletions utest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ VPATH = $(SRC_DIR):$(SRC_DIR)/misc:$(UTEST_DIR)

UTEST_NORM = global_mock.c bxstring_test.o cmdline_test.c tools_test.c regulex_test.o main.o unicode_test.o \
utest_tools.o
MOCKS = bx_fprintf

.PHONY: check_dir flags_unix flags_win32 flags_ utest

Expand All @@ -38,13 +37,13 @@ $(OUT_DIR):

flags_unix:
$(eval CFLAGS := -I. -I$(SRC_DIR) -O -Wall -W -Wno-stringop-overflow $(CFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) $(foreach MOCK,$(MOCKS),-Wl,--wrap=$(MOCK)) --coverage $(LDFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) --coverage $(LDFLAGS_ADDTL))
$(eval UTEST_EXECUTABLE_NAME := unittest)
$(eval UTEST_OBJ := $(UTEST_NORM:.c=.o))

flags_win32:
$(eval CFLAGS := -Os -s -std=c99 -m32 -I. -I$(SRC_DIR) -Wall -W $(CFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) -s -std=c99 -m32 $(foreach MOCK,$(MOCKS),-Wl,--wrap=$(MOCK)) $(LDFLAGS_ADDTL))
$(eval LDFLAGS := $(LDFLAGS) -s -std=c99 -m32 $(LDFLAGS_ADDTL))
$(eval UTEST_EXECUTABLE_NAME := unittest.exe)
$(eval UTEST_OBJ := $(UTEST_NORM:.c=.o))

Expand Down
1 change: 1 addition & 0 deletions utest/global_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void setup_mocks()
setlocale(LC_ALL, "");
encoding = check_encoding("UTF-8", locale_charset());
collect_reset();
set_bx_fprintf(__wrap_bx_fprintf);
}


Expand Down
2 changes: 1 addition & 1 deletion utest/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ then
mkdir -p ${testReportDir}
cp ${OUT_DIR}/*.gc* ${testResultsDir}
lcov --capture --directory ${testResultsDir} --base-directory ${SRC_DIR} --test-name ${tcBaseName} --quiet \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc lcov_branch_coverage=1 \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \
--output-file ${testResultsDir}/coverage.info
echo -n "[ Coverage ] "
genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory ${testReportDir} \
Expand Down