mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
* netbsd fail on error
- Group each BSD test in its own subshell. Without this, if an error
occurs, it exits, but we don't know "where" it failed
- added *usesh: true* to BSD for faster copying into the virtualbox VM
- Some test_suite_runners wheren't correctly printing. added
--no-terminal
- For testing I've changed *build-msvc* from Debug to RelWithDebInfo
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* separate runs
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* fix typo
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* Split msvc-debug into separate workflow
Run msvc-debug only on maintainer pushes, keep CI fast and still catches
errors.
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* Fix build and test errors on NetBSD
* Set proper sizes for various types used for threads
* Add num_cpu function
* Add sysctl constants
* Allow testproject to build on NetBSD
* Tweaks to the linker code so that it adds correct flags and finds dynamic linker on NetBSD
* bsd: force system linker test
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* system linker on openbsd
remove lld from netbsd
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* use cc linker in openbsd, and re-add lld for netbsd
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* openbsd: fixes
- implement num_cpu() for OPENBSD
- testproject: add openbsd
- linker.c: fix for openbsd
- bsd refactor main.yml and more fixes
* openbsd: fix for unit tests and test_suite_runner
openbsd now passes all tests except the 'dynlib-test' which yields
'relocation error' when running `cc test.c -L. -ladd -Wl,-rpath=.`
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* openbsd: guard/disable unit test test_ct_intlog2()
* build-msys2-clang: add all tests that build-msvc has
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* Fix Windows import library generation by adding /IMPLIB support and properly declaring static_lib_name()
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* build-msys2-mingw: add all tests that build-msvc has and enable it
configure CMake to link LLVM and LLD statically
* Revert "Revert windows"
This reverts commit 197f82d829.
* win-llvm 21.1.8
uses the RelWithDebInfo+Assertions
* refactor(CI): Centralize test logic and fix Docker execution
This commit refactors the GitHub Actions workflow to improve
maintainability and correct a flaw in the Docker build.
- Ensures Docker based tests run *inside* the generated container, not
on the host. This also fixes environment isolation and user permission
errors.
- Centralizes all common test steps (examples, libs, unit tests, etc)
into a single, auto-detecting Bash script: `scripts/tools/ci_tests.sh`.
- Centralize all release artifact packaging into a single
`scripts/tools/package_build.sh`
- fixes using correct paths for test_suite_runner when running on
windows under bash.
- This significantly reduces YAML duplication, making `main.yml` more
readable and easier to maintain.
This one supersedes pull/2677, and includes the fixes for:
- fix openbsd and netbsd
- added win-llvm 21.1.8 and fixed CMakeLists.txt
- added full unit-tests and suite for build-msys2-mingw and
build-msys2-clang
* macos: add/fix build for llvm (19,20,21)
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* ci: run tests in temp dir to avoid workspace pollution
Executes ci_tests.sh in a disposable temporary directory by copying
resources/ and test/ folders, preventing build artifacts from cluttering
the source tree.
This makes it easy to run `scripts/tools/ci_tests.sh` locally on any
platform.
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* add ilammy/msvc-dev-cmd@ and Ninja
we can simplify the windows runner and run everything in bash
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* windows: drain subprocess stderr before join to avoid test_suite_runner hang
* move last test to `ci_tests.sh`
thus completing the centralization of tests in `ci_tests.sh`
* Fix Windows CI cache
Updates the cache key to include hashes of CMakeLists.txt and the
workflow file.
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* `package_build.sh` runs in temp dir to avoid workspace pollution
- add cleanup
* nix: use `ci_tests.sh`
* remove annoying build-mac warnings
This now checks if package already installed trying to prevent
annoying warnings in the github ci:
Fixes:
```
build-mac (Release, 19)curl 8.17.0 is already installed and up-to-date.
To reinstall 8.17.0, run: brew reinstall curl
```
* refactor test_suite_runner
- less allocations, cleaner code, more maintainable.
- now can be killed and the temp dirs are correctly cleaned up, and the
output is correct.
* main.yml: bsd: change to using rsync, is twice as fast.
* default to `--wincrt=dynamic` when `--sanitize=address` on windows
Default to dynamic, as static ASan is removed in LLVM 21+ for Windows
https://github.com/llvm/llvm-project/pull/107899
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
* Formatting (indent with tab, align with space). Fix K&R braces. Style: keep all cases multiline if one is.
---------
Signed-off-by: Manuel Barrio Linares <mbarriolinares@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
Co-authored-by: Alex Garrett <limit.ordinal17@gmail.com>
224 lines
6.9 KiB
Bash
Executable File
224 lines
6.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Usage: ./ci_tests.sh <path_to_c3c_binary> [optional_os_mode_override]
|
|
|
|
if [ $# -lt 1 ]; then
|
|
echo "Usage: ./ci_tests.sh <path_to_c3c_binary> [os_mode]"
|
|
exit 1
|
|
fi
|
|
|
|
set -ex
|
|
|
|
# --- Setup Paths & Environment ---
|
|
|
|
# Resolve Script and Real Root Directory
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
REAL_ROOT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
|
|
|
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
|
|
C3C_BIN="$(cygpath -m "$(realpath "$1")")"
|
|
else
|
|
C3C_BIN="$(realpath "$1")"
|
|
fi
|
|
|
|
# Detect OS
|
|
SYSTEM_NAME="$(uname -s)"
|
|
if [ -n "$2" ]; then
|
|
OS_MODE="$2"
|
|
else
|
|
case "$SYSTEM_NAME" in
|
|
CYGWIN*|MINGW*|MSYS*) OS_MODE="windows" ;;
|
|
Darwin*) OS_MODE="mac" ;;
|
|
Linux*) OS_MODE="linux" ;;
|
|
*BSD) OS_MODE="bsd" ;;
|
|
*) OS_MODE="linux" ;;
|
|
esac
|
|
fi
|
|
|
|
echo ">>> Running CI Tests using C3C at: $C3C_BIN"
|
|
echo ">>> OS Mode: $OS_MODE (Detected System: $SYSTEM_NAME)"
|
|
|
|
# --- Create Disposable Workspace ---
|
|
|
|
# Create temp directory
|
|
WORK_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'c3_ci_tests')
|
|
echo ">>> Setting up workspace in: $WORK_DIR"
|
|
|
|
cleanup() {
|
|
echo ">>> Cleaning up..."
|
|
cd "$REAL_ROOT_DIR" || cd ..
|
|
rm -rf "$WORK_DIR"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
# Copy necessary test data to the temp directory
|
|
cp -r "$REAL_ROOT_DIR/resources" "$WORK_DIR/resources"
|
|
cp -r "$REAL_ROOT_DIR/test" "$WORK_DIR/test"
|
|
|
|
# ROOT_DIR points to the temp workspace.
|
|
ROOT_DIR="$WORK_DIR"
|
|
|
|
# Move to the temp resources dir to match original script behavior
|
|
cd "$ROOT_DIR/resources"
|
|
|
|
# --- Tests ---
|
|
|
|
run_examples() {
|
|
echo "--- Running Standard Examples ---"
|
|
"$C3C_BIN" compile examples/base64.c3
|
|
"$C3C_BIN" compile examples/binarydigits.c3
|
|
"$C3C_BIN" compile examples/brainfk.c3
|
|
"$C3C_BIN" compile examples/factorial_macro.c3
|
|
"$C3C_BIN" compile examples/fasta.c3
|
|
"$C3C_BIN" compile examples/gameoflife.c3
|
|
"$C3C_BIN" compile examples/hash.c3
|
|
"$C3C_BIN" compile-only examples/levenshtein.c3
|
|
"$C3C_BIN" compile examples/load_world.c3
|
|
"$C3C_BIN" compile-only examples/map.c3
|
|
"$C3C_BIN" compile examples/mandelbrot.c3
|
|
"$C3C_BIN" compile examples/plus_minus.c3
|
|
"$C3C_BIN" compile examples/nbodies.c3
|
|
"$C3C_BIN" compile examples/spectralnorm.c3
|
|
"$C3C_BIN" compile examples/swap.c3
|
|
"$C3C_BIN" compile examples/contextfree/boolerr.c3
|
|
"$C3C_BIN" compile examples/contextfree/dynscope.c3
|
|
"$C3C_BIN" compile examples/contextfree/guess_number.c3
|
|
"$C3C_BIN" compile examples/contextfree/multi.c3
|
|
"$C3C_BIN" compile examples/contextfree/cleanup.c3
|
|
|
|
"$C3C_BIN" compile-run examples/hello_world_many.c3
|
|
"$C3C_BIN" compile-run examples/time.c3
|
|
"$C3C_BIN" compile-run examples/fannkuch-redux.c3
|
|
"$C3C_BIN" compile-run examples/contextfree/boolerr.c3
|
|
"$C3C_BIN" compile-run examples/load_world.c3
|
|
"$C3C_BIN" compile-run examples/process.c3
|
|
"$C3C_BIN" compile-run examples/ls.c3
|
|
"$C3C_BIN" compile-run examples/args.c3 -- foo -bar "baz baz"
|
|
|
|
if [[ "$OS_MODE" == "linux" ]]; then
|
|
"$C3C_BIN" compile-run --linker=builtin linux_stack.c3 || echo "Warning: linux_stack builtin linker skipped"
|
|
"$C3C_BIN" compile-run linux_stack.c3
|
|
fi
|
|
|
|
"$C3C_BIN" compile --no-entry --test -g --threads 1 --target macos-x64 examples/constants.c3
|
|
}
|
|
|
|
run_cli_tests() {
|
|
echo "--- Running CLI Tests (init/vendor) ---"
|
|
|
|
# Test init
|
|
"$C3C_BIN" init-lib mylib
|
|
"$C3C_BIN" init myproject
|
|
rm -rf mylib.c3l myproject
|
|
|
|
# Test vendor-fetch
|
|
if [ -n "$SKIP_NETWORK_TESTS" ]; then
|
|
echo "Skipping vendor-fetch (network tests disabled)"
|
|
else
|
|
echo "Testing vendor-fetch..."
|
|
cd "$ROOT_DIR/resources"
|
|
"$C3C_BIN" vendor-fetch raylib
|
|
|
|
if [ -f "/etc/alpine-release" ] || [[ "$SYSTEM_NAME" == "OpenBSD" ]] || [[ "$SYSTEM_NAME" == "NetBSD" ]]; then
|
|
echo "Skipping raylib_arkanoid (vendor raylib doesn't support this platform)"
|
|
return
|
|
fi
|
|
"$C3C_BIN" compile --lib raylib --print-linking examples/raylib/raylib_arkanoid.c3
|
|
fi
|
|
}
|
|
|
|
run_dynlib_tests() {
|
|
echo "--- Running Dynamic Lib Tests ---"
|
|
# Skip openbsd, idk
|
|
if [[ "$SYSTEM_NAME" == *"OpenBSD"* ]]; then return; fi
|
|
|
|
cd "$ROOT_DIR/resources/examples/dynlib-test"
|
|
"$C3C_BIN" -vv dynamic-lib add.c3
|
|
|
|
if [[ "$OS_MODE" == "windows" ]]; then
|
|
"$C3C_BIN" -vv compile-run test.c3 -l ./add.lib
|
|
elif [[ "$OS_MODE" == "mac" ]]; then
|
|
"$C3C_BIN" -vv compile-run test.c3 -l ./add.dylib
|
|
else
|
|
if [ -f add.so ]; then mv add.so libadd.so; fi
|
|
cc test.c -L. -ladd -Wl,-rpath=.
|
|
./a.out
|
|
"$C3C_BIN" compile-run test.c3 -L . -l add -z -Wl,-rpath=.
|
|
fi
|
|
}
|
|
|
|
run_staticlib_tests() {
|
|
echo "--- Running Static Lib Tests ---"
|
|
cd "$ROOT_DIR/resources/examples/staticlib-test"
|
|
|
|
if [[ "$OS_MODE" == "windows" ]]; then
|
|
"$C3C_BIN" -vv static-lib add.c3
|
|
"$C3C_BIN" -vv compile-run test.c3 -l ./add.lib
|
|
else
|
|
"$C3C_BIN" -vv static-lib add.c3 -o libadd
|
|
if [[ "$SYSTEM_NAME" == *"NetBSD"* ]]; then ranlib libadd.a; fi
|
|
|
|
OUTPUT_BIN="a.out"
|
|
if [[ "$SYSTEM_NAME" == *"OpenBSD"* ]]; then
|
|
cc test.c -L. -ladd -lexecinfo -lm -lpthread -o "$OUTPUT_BIN"
|
|
elif [[ "$SYSTEM_NAME" == "Linux" ]]; then
|
|
# Fix: Linux (and i mean specifically the docker container run) needs dl (for backtrace)
|
|
# math and pthread linked manually for static libs
|
|
cc test.c -L. -ladd -ldl -lm -lpthread -o "$OUTPUT_BIN"
|
|
else
|
|
# Mac / NetBSD
|
|
cc test.c -L. -ladd -o "$OUTPUT_BIN"
|
|
fi
|
|
./"$OUTPUT_BIN"
|
|
"$C3C_BIN" compile-run test.c3 -L . -l add
|
|
fi
|
|
}
|
|
|
|
run_testproject() {
|
|
echo "--- Running Test Project ---"
|
|
cd "$ROOT_DIR/resources/testproject"
|
|
|
|
ARGS="--trust=full"
|
|
|
|
if [[ "$OS_MODE" == "linux" || "$OS_MODE" == "mac" ]]; then
|
|
ARGS="$ARGS --linker=builtin"
|
|
|
|
if [ -f "/etc/alpine-release" ]; then
|
|
ARGS="$ARGS --linux-libc=musl"
|
|
fi
|
|
fi
|
|
|
|
"$C3C_BIN" run -vv $ARGS
|
|
"$C3C_BIN" clean
|
|
|
|
if [[ "$OS_MODE" == "windows" ]]; then
|
|
echo "Running Test Project (hello_world_win32)..."
|
|
"$C3C_BIN" -vv --emit-llvm run hello_world_win32 $ARGS
|
|
"$C3C_BIN" clean
|
|
"$C3C_BIN" -vv build hello_world_win32_lib $ARGS
|
|
fi
|
|
}
|
|
|
|
run_wasm_compile() {
|
|
echo "--- Running WASM Compile Check ---"
|
|
cd "$ROOT_DIR/resources/testfragments"
|
|
"$C3C_BIN" compile --target wasm32 -g0 --no-entry -Os wasm4.c3
|
|
}
|
|
|
|
run_unit_tests() {
|
|
echo "--- Running Unit Tests ---"
|
|
cd "$ROOT_DIR/test"
|
|
"$C3C_BIN" compile-test unit -O1 -D SLOW_TESTS
|
|
|
|
echo "--- Running Test Suite Runner ---"
|
|
"$C3C_BIN" compile-run -O1 src/test_suite_runner.c3 -- "$C3C_BIN" test_suite/ --no-terminal
|
|
}
|
|
|
|
# --- Execution ---
|
|
run_examples
|
|
run_cli_tests
|
|
run_dynlib_tests
|
|
run_staticlib_tests
|
|
run_testproject
|
|
run_wasm_compile
|
|
run_unit_tests
|