From 79f6bb57d47b1205c7999fef29201e607e859d91 Mon Sep 17 00:00:00 2001 From: Eric Ratliff Date: Sun, 15 Mar 2026 17:09:29 -0500 Subject: [PATCH] Tests now work for FreeBSD --- templates/basic/test.sh | 15 ++++++++++++++- templates/basic/test/run_tests.sh | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/templates/basic/test.sh b/templates/basic/test.sh index 72a8051..15c16c8 100644 --- a/templates/basic/test.sh +++ b/templates/basic/test.sh @@ -24,6 +24,17 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" TEST_DIR="$SCRIPT_DIR/test" BUILD_DIR="$TEST_DIR/build" +# Portable CPU count -- BSD make requires a number after -j, GNU make does not +cpu_count() { + if command -v nproc &>/dev/null; then + nproc + elif command -v sysctl &>/dev/null; then + sysctl -n hw.ncpu + else + echo 4 + fi +} + # Color output if [[ -t 1 ]]; then RED=$'\033[0;31m'; GRN=$'\033[0;32m'; CYN=$'\033[0;36m' @@ -67,6 +78,8 @@ if ! command -v cmake &>/dev/null; then echo " Install:" >&2 if [[ "$(uname)" == "Darwin" ]]; then echo " brew install cmake" >&2 + elif [[ "$(uname)" == "FreeBSD" ]]; then + echo " sudo pkg install cmake" >&2 else echo " sudo apt install cmake (Debian/Ubuntu)" >&2 echo " sudo dnf install cmake (Fedora)" >&2 @@ -102,7 +115,7 @@ if [[ ! -f "$BUILD_DIR/CMakeCache.txt" ]]; then fi info "Building tests..." -cmake --build "$BUILD_DIR" --parallel 2>&1 | \ +cmake --build "$BUILD_DIR" --parallel "$(cpu_count)" 2>&1 | \ while IFS= read -r line; do echo " $line"; done echo "" diff --git a/templates/basic/test/run_tests.sh b/templates/basic/test/run_tests.sh index cd89953..645fab9 100644 --- a/templates/basic/test/run_tests.sh +++ b/templates/basic/test/run_tests.sh @@ -17,6 +17,17 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" BUILD_DIR="$SCRIPT_DIR/build" +# Portable CPU count -- BSD make requires a number after -j, GNU make does not +cpu_count() { + if command -v nproc &>/dev/null; then + nproc + elif command -v sysctl &>/dev/null; then + sysctl -n hw.ncpu + else + echo 4 + fi +} + # Color output if [[ -t 1 ]]; then RED=$'\033[0;31m'; GRN=$'\033[0;32m'; CYN=$'\033[0;36m' @@ -40,7 +51,7 @@ for arg in "$@"; do esac done -command -v cmake &>/dev/null || die "cmake not found. Install: sudo apt install cmake" +command -v cmake &>/dev/null || die "cmake not found. Install: pkg install cmake (FreeBSD), apt install cmake (Debian/Ubuntu), dnf install cmake (Fedora)" command -v g++ &>/dev/null || command -v clang++ &>/dev/null || die "No C++ compiler found" command -v git &>/dev/null || die "git not found (needed to fetch Google Test)" @@ -55,7 +66,7 @@ if [[ ! -f "$BUILD_DIR/CMakeCache.txt" ]]; then fi info "Building tests..." -cmake --build "$BUILD_DIR" --parallel +cmake --build "$BUILD_DIR" --parallel "$(cpu_count)" echo "" info "${BLD}Running tests...${RST}"