Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Makefile CI

on:
pull_request:
branches: [ "main" ]
release:
types: [published, created]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: make

- name: Run check
run: make check

- name: Run distcheck
run: make distcheck
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ LIB_SOURCES := assertc \

# Test programs to build from tests directory
TEST_PROGRAMS := example_test_ok \
example_test_fail \
example_test_all \

# Object files
Expand All @@ -30,7 +29,7 @@ TEST_BINARIES := $(patsubst %,$(BIN_DIR)/%,$(TEST_PROGRAMS))
DEBUG_BINARIES := $(patsubst %,$(BUILD_DIR)/%,$(TEST_PROGRAMS))

# Default target
.PHONY: all clean debug release tests directories help
.PHONY: all clean debug release tests directories help check distcheck

all: directories debug release

Expand Down Expand Up @@ -67,9 +66,17 @@ release: directories $(TEST_BINARIES)
tests: $(TEST_BINARIES)
@for test in $(TEST_BINARIES); do \
echo "Running $$test..."; \
./$$test; \
./$$test || exit 1; \
done

# Check target - build and run tests
check: release tests
@echo "All tests passed successfully!"

# Distcheck target - comprehensive testing with clean build
distcheck: clean all tests
@echo "All tests passed successfully!"

# Clean build artifacts
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR) $(BUILD_DIR)
Expand All @@ -81,6 +88,8 @@ help:
@echo " debug - Build debug versions"
@echo " release - Build release versions"
@echo " tests - Run all tests"
@echo " check - Build and run tests"
@echo " distcheck - Clean build and comprehensive testing"
@echo " clean - Remove all build artifacts"
@echo " directories - Create build directories"
@echo " help - Show this help message"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ FAILED
test result: FAILED. 2 passed; 1 failed
```

Look at the `tests/` directory for more examples.

⚠️ **Important Note**: `example_test_fail.c` is excluded from Makefile, to pass build.

### Building and Running

Compile your test file with the framework:
Expand Down Expand Up @@ -91,10 +95,6 @@ TEST_DEPS_your_test = $(SRCDIR)/your_module.c $(assertc)
5. **Keep tests independent** - Each test should be able to run in isolation
6. **Use consistent test data** - Define test arrays as static variables for reuse

## Example Test File

See `tests/example_test.c` for a comprehensive example of how to structure unit tests using this framework.

## Key Differences from Traditional C Testing

### Traditional Approach
Expand Down