1 Star 0 Fork 176

Days0102/Class-test-ci

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Makefile 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
徐堃元 提交于 2024-05-28 17:28 . update makefile
# Makefile for C language exercise project
# Define the directory where the exercise files are stored
EXERCISE_DIR = ./exercises
# Define the test directory
TEST_DIR = ./test
# Define the build directory
BUILD_DIR = ./build
# Ensure the test and build directories exist
$(shell mkdir -p $(TEST_DIR) $(BUILD_DIR))
# Define the list of exercises
EXERCISES = $(wildcard $(EXERCISE_DIR)/*.c)
# Define the list of executables
EXECUTABLES = $(patsubst $(EXERCISE_DIR)/%.c, $(BUILD_DIR)/%, $(EXERCISES))
# Define compiler and linker flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99
LDFLAGS = -lm
# Default target: build all executables
all: $(EXECUTABLES) clean
# Build rule for each executable
$(BUILD_DIR)/%: $(EXERCISE_DIR)/%.c
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
# Clean rule to remove all executables and object files
clean:
rm -f $(EXECUTABLES) $(BUILD_DIR)/*.o
# Generate test cases rule
generate-test-cases: $(EXECUTABLES)
@for exe in $(EXECUTABLES); do \
./$$exe > $(TEST_DIR)/$$(basename $$exe).out; \
done
@$(MAKE) clean
# Test rule to compare output with expected results
test-output: $(EXECUTABLES)
@for exe in $(EXECUTABLES); do \
exercise_name=$$(basename $$exe); \
expected=$$(cat $(TEST_DIR)/$${exercise_name}.out); \
actual=$$($$exe); \
if [ "$$expected" = "$$actual" ]; then \
echo "Test for $${exercise_name} passed."; \
else \
echo "Test for $${exercise_name} failed."; \
echo "Expected:"; echo "$$expected"; \
echo "Actual:"; echo "$$actual"; \
fi; \
done
@$(MAKE) clean
# New target to save test results and count pass rate in JSON format
save-test-results: $(EXECUTABLES)
@total=0; \
passed=0; \
> $(BUILD_DIR)/test_results.json; \
for exe in $(EXECUTABLES); do \
exercise_name=$$(basename $$exe); \
expected=$$(cat $(TEST_DIR)/$${exercise_name}.out); \
actual=$$($$exe); \
total=$$((total+1)); \
if [ "$$expected" = "$$actual" ]; then \
passed=$$((passed+1)); \
fi; \
done; \
echo "{\"channel\": \"gitee\",\"courseId\": 1558,\"ext\": \"aaa\",\"name\": \"\",\"score\": $$passed,\"totalScore\": 5}" > $(BUILD_DIR)/test_results.json
@$(MAKE) clean
.PHONY: all clean generate-test-cases test-output save-test-results
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/days0102/class-test-ci.git
git@gitee.com:days0102/class-test-ci.git
days0102
class-test-ci
Class-test-ci
master

搜索帮助