Skip to content

Commit

Permalink
Add a make check and some related infrastructure
Browse files Browse the repository at this point in the history
Allow ORCHLUA_PATH to be overridden in the environment, so that we can test
the orch.lua directly out of the repository.  Flip our preference of orch
binary to use in the basic test, we want to prefer testing with the binary
we just built.

Switch CI to just use `make check` instead of having to copy orch.lua out.

Signed-off-by: Kyle Evans <[email protected]>
  • Loading branch information
kevans91 committed Jan 19, 2024
1 parent 2a262c9 commit 3f77ca1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
5 changes: 1 addition & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ build_task:
sudo pkg install -y lua54
build_script:
env ORCHLUA_PATH=/usr/local/share/orch make
install_script:
- mkdir -p /usr/local/share/orch
- cp orch.lua /usr/local/share/orch
test_script:
sh tests/basic_test.sh
make check
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ jobs:
LUA_LIB="${lua_lib}" bmake
- name: Run self-tests
run: |
sudo mkdir -p /usr/local/share/orch
sudo cp orch.lua /usr/local/share/orch
sh tests/basic_test.sh
make check
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SRCS+= orch_compat.c
CFLAGS+= -DORCHLUA_PATH=\"${ORCHLUA_PATH}\"

.if empty(ORCHLUA_PATH:M/*)
.error "ORCHLUA_PATH must be empty or absolute"
.error "ORCHLUA_PATH must be an absolute path"
.endif

FILESGROUPS+= FILES
Expand All @@ -38,6 +38,10 @@ LDADD+= ${LUA_LIB}
lint:
luacheck orch.lua

# Just pass this on for now.
check:
env ORCHLUA_PATH=${.CURDIR} $(MAKE) -C tests check

.include "examples/Makefile.inc"

.include <bsd.prog.mk>
20 changes: 17 additions & 3 deletions orch_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ orch_interp_script(const char *orch_invoke_path)

/* Populate buf first... we cache the script path */
if (buf[0] == '\0') {
/* If LIBEXEC_PATH is empty, it's in the same path as our binary. */
if (orchlua_path[0] == '\0') {
const char *path;

path = getenv("ORCHLUA_PATH");
if (path != NULL && (path[0] == '\0' || path[0] != '/')) {
fprintf(stderr,
"Ignoring empty or relative ORCHLUA_PATH in the environment ('%s')\n",
path);
path = NULL;
}

/* Fallback to what's built-in, if no env override. */
if (path == NULL)
path = orchlua_path;

/* If ORCHLUA_PATH is empty, it's in the same path as our binary. */
if (path[0] == '\0') {
char *slash;

if (realpath(orch_invoke_path, buf) == NULL)
Expand All @@ -45,7 +59,7 @@ orch_interp_script(const char *orch_invoke_path)
assert(*slash != '\0');
*slash = '\0';
} else {
strlcpy(buf, orchlua_path, sizeof(buf));
strlcpy(buf, path, sizeof(buf));
}

strlcat(buf, "/orch.lua", sizeof(buf));
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
check:
@sh basic_test.sh
17 changes: 11 additions & 6 deletions tests/basic_test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/sh

scriptdir=$(dirname $(realpath "$0"))
orchbin="$(which orch)"
if [ -n "$orchbin" ]; then
orchdir="$(dirname "$orchbin")"
else
orchdir="$scriptdir/.."
orchbin="$orchdir/orch"
orchbin="$scriptdir/../orch"
if [ ! -x "$orchbin" ]; then
orchbin="$(which orch)"
fi
if [ ! -x "$orchbin" ]; then
1>&2 echo "Failed to find a usable orch binary"
exit 1
fi

orchdir="$(dirname "$orchbin")"

1>&2 echo "Using binary: $orchbin"

fails=0
testid=1
Expand Down

0 comments on commit 3f77ca1

Please sign in to comment.