mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
91 black-box checks in tests/run.sh, driving the built binary because that is the only interface the tool has. POSIX sh, no dependencies, no framework; TAP-ish output and a non-zero exit when anything fails. Covers the tree shapes SPEC.md section 22 asks for -- regular and empty files, nested directories, symlinks, broken symlinks, symlinks to directories, hard links, FIFOs, sockets, unusual filenames and permission errors -- the parser cases from sections 14 and 15, the diff classifications, argument handling, and the resource rules from sections 9 and 11. What the environment cannot provide is skipped, not failed. Every bug fixed in this branch is pinned by a test: the 2^32 comparison truncation, the symlink checksum, target-before-fingerprint ordering, the mkstemp template unlink, errno surviving a cleanup failure, the empty snapshot in diff, and create over each entry type that used to abort it. Invocations run under timeout(1) where it exists. Without it a walker regression makes create block on a FIFO forever, which hangs the suite instead of failing it -- found by reintroducing exactly that bug. Checked by mutation: seven deliberate regressions, one per fix, each caught by the test written for it, with the baseline green either side. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
77 lines
2.0 KiB
Makefile
77 lines
2.0 KiB
Makefile
CC := cc
|
|
|
|
# Feature test macros belong to the build, not to individual files: declaring
|
|
# them per-source drifted into four different combinations across nine files.
|
|
# _POSIX_C_SOURCE covers getline and realpath(path, NULL); _DEFAULT_SOURCE adds
|
|
# dirent.d_type, which walk uses as a fast path. SPEC.md section 19 targets
|
|
# POSIX, so nothing here asks for _GNU_SOURCE.
|
|
FEATURES := -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
|
|
|
|
CPPFLAGS := -Iinclude -MMD -MP $(FEATURES)
|
|
|
|
# -O2 is not only about speed: without optimisation GCC skips the flow
|
|
# analysis that most of these warnings are derived from.
|
|
WARNINGS := -Wall -Wextra -Wpedantic -Wconversion -Wshadow -Wvla \
|
|
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition \
|
|
-Wcast-qual -Wwrite-strings -Wdouble-promotion
|
|
CFLAGS := -std=c11 $(WARNINGS) -O2 -ggdb
|
|
LDFLAGS :=
|
|
LDLIBS :=
|
|
|
|
BUILD_DIR := build
|
|
NAME := fsnap
|
|
TARGET := $(BUILD_DIR)/$(NAME)
|
|
|
|
# ?= so a caller can override from the environment or the command line.
|
|
# DESTDIR is deliberately not defaulted: it is empty for a real install and set
|
|
# by a packager staging into a temporary root.
|
|
PREFIX ?= /usr/local
|
|
BINDIR ?= $(PREFIX)/bin
|
|
INSTALL ?= install
|
|
|
|
SOURCES := \
|
|
src/main.c \
|
|
src/utility.c \
|
|
src/types.c \
|
|
src/hash.c \
|
|
src/walk.c \
|
|
src/scan.c \
|
|
src/create.c \
|
|
src/list.c \
|
|
src/diff.c
|
|
|
|
TESTS := tests/run.sh
|
|
|
|
OBJECTS := $(SOURCES:%.c=$(BUILD_DIR)/%.o)
|
|
DEPENDENCIES := $(OBJECTS:.o=.d)
|
|
|
|
.PHONY: all clean run test install uninstall
|
|
|
|
all: $(TARGET)
|
|
|
|
$(TARGET): $(OBJECTS)
|
|
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@
|
|
|
|
$(BUILD_DIR)/%.o: %.c
|
|
@mkdir -p $(dir $@)
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
|
|
|
run: $(TARGET)
|
|
./$(TARGET)
|
|
|
|
# Black-box: the suite drives the built binary, so it needs nothing but sh.
|
|
test: $(TARGET)
|
|
@FSNAP='$(CURDIR)/$(TARGET)' sh $(TESTS)
|
|
|
|
install: $(TARGET)
|
|
$(INSTALL) -d $(DESTDIR)$(BINDIR)
|
|
$(INSTALL) -m 755 $(TARGET) $(DESTDIR)$(BINDIR)/$(NAME)
|
|
|
|
uninstall:
|
|
rm -f $(DESTDIR)$(BINDIR)/$(NAME)
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
-include $(DEPENDENCIES)
|