Skip to content
Open
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
57 changes: 27 additions & 30 deletions MakefileCppUTest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,28 @@ COMPONENT_NAME = BookCode_CppUTest
CPP_PLATFORM = Gcc
PROJECT_HOME_DIR = .

# 1. 源代码目录 (移除了 MyOS)
SRC_DIRS = \
src/HomeAutomation \
src/util\
src/LedDriver \
src/dvr\
src/IO \
src/MyOS \
src/MyOS/posix \
src/zune \
src/HomeAutomation \
src/util\
src/LedDriver \
src/dvr\
src/IO \
src/zune \

# 2. 测试代码目录 (移除了 MyOS, stdio)
TEST_SRC_DIRS = \
.\
mocks\
mocks\
tests/LedDriver\
tests/stdio\
tests/util\
tests/IO\
tests/zune\
tests/HomeAutomation\
tests/dvr\
tests\
tests/MyOS\
.\
mocks\
tests/LedDriver\
tests/util\
tests/IO\
tests/zune\
tests/HomeAutomation\
tests/dvr\
tests\

# 3. 头文件目录 (移除了 MyOS)
INCLUDE_DIRS =\
.\
$(CPPUTEST_HOME)/include\
Expand All @@ -43,23 +40,23 @@ INCLUDE_DIRS =\
include/util\
include/HomeAutomation\
include/LedDriver\
include/MyOS\
include/dvr\
include/zune\

MOCKS_SRC_DIRS = \
mocks\

mocks\

# 编译选项配置 (保持不变)
CPPUTEST_WARNINGFLAGS = -Wall -Wswitch-default -Werror
CPPUTEST_WARNINGFLAGS += -Wall -Werror -Wswitch-default -Wswitch-enum
CPPUTEST_WARNINGFLAGS += -Wno-reserved-id-macro -Wno-keyword-macro -Wno-unused-parameter -Wno-pedantic -Wno-shadow -Wno-format-nonliteral -Wno-missing-field-initializers
#CPPUTEST_CFLAGS = -std=c89
CPPUTEST_CFLAGS += -Wall -Wstrict-prototypes -pedantic
#CPPUTEST_CFLAGS = -std=c89
CPPUTEST_CFLAGS += -Wall -Wstrict-prototypes -pedantic
LD_LIBRARIES = -lpthread

# 引入 CppUTest 的构建逻辑
ifeq ($(CPPUTEST_HOME),)
$(info CPPUTEST_HOME not set! See README.txt)
else
else
include $(CPPUTEST_HOME)/build/MakefileWorker.mk
endif
endif
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
目前的源代码在以下三种开发环境中都可以正常运行:
1. Windows7/Windows10上使用MSYS2安装的gcc/g++ 7.4
MSYS2安装包下载地址:https://www.msys2.org/
安装好MSYS2之后,可以在其安装的bash命令行窗口(桌面上会添加bash命令行窗口的图标)中使用如下命令下载安装gcc:
pacman -S gcc
安装好 MSYS2 之后,建议使用 **UCRT64** 环境(兼容性更好)。在 UCRT64 终端中使用如下命令安装 gcc 工具链和构建工具(注意:必须显式安装 make): `pacman -S mingw-w64-ucrt-x86_64-gcc make`
1. Linux上使用系统自带的gcc/g++ 7.5
1. macOS上使用系统自带的clang/clang++ 11.0.3

Expand Down Expand Up @@ -70,4 +69,6 @@ make -i -C t3 clean

源代码在读者的本地环境编译没问题了,读者可以保留一个备份。然后跟着这本书的进度,把C语言源文件和对应的单元测试文件中多余的源代码、单元测试代码都删除。按照TDD的要求,小步快跑,每次先加一个单元测试,然后再加足够的源代码让单元测试通过,接下来做代码重构。严格遵照这个三步走的节奏来开发系统,深入体会TDD是如何驱动设计和代码的发展。这会是一场很有趣的经历,TDD让编程充满了乐趣。

**💡 懒人福利 / 练习脚手架:** 如果你不想手动删除源代码,或者在配置 MSYS2 环境时遇到困难,可以使用我整理好的 **纯净版 TDD 练习脚手架 (Starter Kit)**: 👉 **[lleoeric/embedded-c-tdd-starter: A modern, clean-slate starter kit for James Grenning's TDD book. MSYS2/GCC ready.](https://github.com/lleoeric/embedded-c-tdd-starter)** 该仓库已修复了 Makefile 以适配现代 GCC 环境,并**预先清空了实现代码**(保留了测试结构),你可以 Clone 下来直接配合本书开始练习,无需手动清理。

Happy coding!