1 Star 0 Fork 175

ChenMiaoi/Class-test

forked from 徐堃元/Class-test 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Makefile 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
徐堃元 提交于 2024-05-22 13:14 . update courseid
# 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))
# Default target: build all executables
all: $(EXECUTABLES) clean
# Build rule for each executable
$(BUILD_DIR)/%: $(EXERCISE_DIR)/%.c
gcc -o $@ $<
# 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\": 100}" > $(BUILD_DIR)/test_results.json
@$(MAKE) clean
.PHONY: all clean generate-test-cases test-output save-test-results
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenmiaoi/class-test.git
git@gitee.com:chenmiaoi/class-test.git
chenmiaoi
class-test
Class-test
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385