fix(test): ensure Windows compatibility in test suite

- Add OS detection for Windows vs Unix platforms
- Handle .exe extension on Windows for test program
- Fix directory creation with Windows-native commands (mkdir/copy vs mkdir -p/cp)
- Update clean target to use appropriate commands per platform
- Set PATH environment for DLL loading on Windows
- Remove broken uname detection that fails on Windows
This commit is contained in:
2026-02-01 01:41:03 +01:00
parent dc30ce5366
commit 1919287c39
+24 -20
View File
@@ -2,42 +2,46 @@ CC := cc
CFLAGS = -Wall -Wpedantic -I../include -std=c89 CFLAGS = -Wall -Wpedantic -I../include -std=c89
LDFLAGS = -L../bin/debug -lstk LDFLAGS = -L../bin/debug -lstk
UNAME_S := $(shell uname -s)
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
MODULE_EXT = .dll MODULE_EXT = .dll
EXE_EXT = .exe
else else
LDFLAGS += -Wl,-rpath,../bin/debug
MODULE_EXT = .so MODULE_EXT = .so
EXE_EXT =
LDFLAGS += -Wl,-rpath,../bin/debug
endif endif
.PHONY: all test clean .PHONY: all test clean
all: test all: test
test_program: test.c test_program$(EXE_EXT): test.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(CC) $(CFLAGS) -o $@ test.c $(LDFLAGS)
test_mod$(MODULE_EXT): test_mod.c test_mod$(MODULE_EXT): test_mod.c
$(CC) $(CFLAGS) -fPIC -shared -o $@ $< $(CC) $(CFLAGS) -fPIC -shared -o $@ test_mod.c
setup: setup:
ifeq ($(OS),Windows_NT)
@if not exist mods mkdir mods
@if exist test_mod.dll copy /Y test_mod.dll mods\ >nul 2>&1
else
@mkdir -p mods @mkdir -p mods
@cp -f test_mod$(MODULE_EXT) mods/ 2>/dev/null || true @cp -f test_mod.so mods/ 2>/dev/null || true
@echo " Test environment ready: mods/ directory with test_mod$(MODULE_EXT)" endif
run: test_program test_mod$(MODULE_EXT) setup test: test_program$(EXE_EXT) test_mod$(MODULE_EXT) setup
@echo "Running integration test (CTRL+C to exit)..." ifeq ($(OS),Windows_NT)
@set PATH=../bin/debug;%PATH% && cmd /C "test_program.exe"
else
@./test_program @./test_program
endif
test: test_program test_mod$(MODULE_EXT) setup
@echo "=== stk Integration Test ==="
@echo "1. Starting test program"
@echo "2. Will load test_mod$(MODULE_EXT) from mods/"
@echo "3. Press CTRL+C to exit"
@echo "============================="
@./test_program || echo "Test completed."
clean: clean:
rm -f test_program test_mod$(MODULE_EXT) ifeq ($(OS),Windows_NT)
rm -rf mods/ @del /Q test_program.exe test_mod.dll 2>nul || true
@rmdir /S /Q mods 2>nul || true
else
@rm -f test_program test_mod.so
@rm -rf mods
endif