diff options
-rw-r--r-- | .github/workflows/codecov.yml | 2 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 106 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | docs/BUILDING.md | 8 | ||||
-rw-r--r-- | docs/HACKING.md | 2 | ||||
-rw-r--r-- | docs/USAGE.md | 3 | ||||
-rwxr-xr-x | tests/tests.sh (renamed from tests.sh) | 14 |
8 files changed, 68 insertions, 73 deletions
diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 9bb407a..5853504 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -25,7 +25,7 @@ jobs: - name: Generate coverage run: | make -j$(nproc) gcov check - gcov -abcfu build/*/*.o + gcov -abcfu obj/*/*.o - uses: codecov/codecov-action@v2 with: @@ -1,2 +1,2 @@ -/build/ -/bfs +/bin/ +/obj/ @@ -167,9 +167,6 @@ ALL_CFLAGS = $(ALL_CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAG ALL_LDFLAGS = $(ALL_CFLAGS) $(LOCAL_LDFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) ALL_LDLIBS = $(LOCAL_LDLIBS) $(LDLIBS) $(EXTRA_LDLIBS) -# Goals that make binaries -BIN_GOALS := bfs build/tests/mksock build/tests/trie build/tests/xtimegm - # Goals that are treated like flags by this Makefile FLAG_GOALS := asan lsan msan tsan ubsan gcov release @@ -179,7 +176,7 @@ GOALS := $(filter-out $(FLAG_GOALS),$(MAKECMDGOALS)) # Build the default goal if only flag goals are specified FLAG_PREREQS := ifndef GOALS -FLAG_PREREQS += default +FLAG_PREREQS += bfs endif # The different search strategies that we test @@ -192,60 +189,61 @@ CHECKS := $(STRATEGY_CHECKS) check-trie check-xtimegm # Custom test flags for distcheck DISTCHECK_FLAGS := -s TEST_FLAGS="--sudo --verbose=skipped" -default: bfs -.PHONY: default +bfs: bin/bfs +.PHONY: bfs -all: $(BIN_GOALS) +all: bin/bfs bin/tests/mksock bin/tests/trie bin/tests/xtimegm .PHONY: all -bfs: \ - build/src/bar.o \ - build/src/bftw.o \ - build/src/color.o \ - build/src/ctx.o \ - build/src/darray.o \ - build/src/diag.o \ - build/src/dir.o \ - build/src/dstring.o \ - build/src/eval.o \ - build/src/exec.o \ - build/src/fsade.o \ - build/src/main.o \ - build/src/mtab.o \ - build/src/opt.o \ - build/src/parse.o \ - build/src/printf.o \ - build/src/pwcache.o \ - build/src/stat.o \ - build/src/trie.o \ - build/src/typo.o \ - build/src/util.o \ - build/src/xregex.o \ - build/src/xspawn.o \ - build/src/xtime.o - -build/tests/mksock: build/tests/mksock.o -build/tests/trie: build/src/trie.o build/tests/trie.o -build/tests/xtimegm: build/src/xtime.o build/tests/xtimegm.o - -$(BIN_GOALS): +bin/bfs: \ + obj/src/bar.o \ + obj/src/bftw.o \ + obj/src/color.o \ + obj/src/ctx.o \ + obj/src/darray.o \ + obj/src/diag.o \ + obj/src/dir.o \ + obj/src/dstring.o \ + obj/src/eval.o \ + obj/src/exec.o \ + obj/src/fsade.o \ + obj/src/main.o \ + obj/src/mtab.o \ + obj/src/opt.o \ + obj/src/parse.o \ + obj/src/printf.o \ + obj/src/pwcache.o \ + obj/src/stat.o \ + obj/src/trie.o \ + obj/src/typo.o \ + obj/src/util.o \ + obj/src/xregex.o \ + obj/src/xspawn.o \ + obj/src/xtime.o + +bin/tests/mksock: obj/tests/mksock.o +bin/tests/trie: obj/src/trie.o obj/tests/trie.o +bin/tests/xtimegm: obj/src/xtime.o obj/tests/xtimegm.o + +bin/%: + @$(MKDIR) $(@D) +$(CC) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@ -build/%.o: %.c build/FLAGS +obj/%.o: %.c obj/FLAGS @$(MKDIR) $(@D) $(CC) $(ALL_CFLAGS) -c $< -o $@ # Save the full set of flags to rebuild everything when they change -build/FLAGS.new: +obj/FLAGS.new: @$(MKDIR) $(@D) @echo $(CC) : $(ALL_CFLAGS) : $(ALL_LDFLAGS) : $(ALL_LDLIBS) >$@ -.PHONY: build/FLAGS.new +.PHONY: obj/FLAGS.new -# Only update build/FLAGS if build/FLAGS.new is different -build/FLAGS: build/FLAGS.new +# Only update obj/FLAGS if obj/FLAGS.new is different +obj/FLAGS: obj/FLAGS.new @test -e $@ && cmp -s $@ $< && rm $< || mv $< $@ -# Make sure that "make release" builds everything, but "make release build/src/main.o" doesn't +# Make sure that "make release" builds everything, but "make release obj/src/main.o" doesn't $(FLAG_GOALS): $(FLAG_PREREQS) @: .PHONY: $(FLAG_GOALS) @@ -253,10 +251,10 @@ $(FLAG_GOALS): $(FLAG_PREREQS) check: $(CHECKS) .PHONY: check $(CHECKS) -$(STRATEGY_CHECKS): check-%: bfs build/tests/mksock - ./tests.sh --bfs="./bfs -S $*" $(TEST_FLAGS) +$(STRATEGY_CHECKS): check-%: bin/bfs bin/tests/mksock + ./tests/tests.sh --bfs="./bin/bfs -S $*" $(TEST_FLAGS) -check-trie check-xtimegm: check-%: build/tests/% +check-trie check-xtimegm: check-%: bin/tests/% $< distcheck: @@ -273,12 +271,12 @@ endif .PHONY: distcheck clean: - $(RM) -r bfs build + $(RM) -r bin obj .PHONY: clean install: $(MKDIR) $(DESTDIR)$(PREFIX)/bin - $(INSTALL) -m755 bfs $(DESTDIR)$(PREFIX)/bin/bfs + $(INSTALL) -m755 bin/bfs $(DESTDIR)$(PREFIX)/bin/bfs $(MKDIR) $(DESTDIR)$(MANDIR)/man1 $(INSTALL) -m644 docs/bfs.1 $(DESTDIR)$(MANDIR)/man1/bfs.1 $(MKDIR) $(DESTDIR)$(PREFIX)/share/bash-completion/completions @@ -295,12 +293,12 @@ uninstall: .PHONY: uninstall check-install: - +$(MAKE) install DESTDIR=build/pkg - +$(MAKE) uninstall DESTDIR=build/pkg - ./bfs build/pkg -not -type d -print -exit 1 - $(RM) -r build/pkg + +$(MAKE) install DESTDIR=pkg + +$(MAKE) uninstall DESTDIR=pkg + ./bin/bfs pkg -not -type d -print -exit 1 + $(RM) -r pkg .PHONY: check-install .SUFFIXES: --include $(wildcard build/*/*.d) +-include $(wildcard obj/*/*.d) @@ -279,7 +279,7 @@ Then run $ make -This will build the `bfs` binary in the current directory. +This will build the `./bin/bfs` binary. Run the test suite to make sure it works correctly: $ make check diff --git a/docs/BUILDING.md b/docs/BUILDING.md index ebab60b..edbce3a 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -113,24 +113,24 @@ Most of them are *snapshot tests* which compare `bfs`'s output to a known-good c You can pass the name of a particular test case (or a few) to run just those tests. For example: - $ ./tests.sh test_basic + $ ./tests/tests.sh test_basic If you need to update the reference snapshot, pass `--update`. It can be handy to generate the snapshot with a different `find` implementation to ensure the output is correct, for example: - $ ./tests.sh test_basic --bfs=find --update + $ ./tests/tests.sh test_basic --bfs=find --update But keep in mind, other `find` implementations may not be correct. To my knowledge, no other implementation passes even the POSIX-compatible subset of the tests: - $ ./tests.sh --bfs=find --posix + $ ./tests/tests.sh --bfs=find --posix ... tests passed: 89 tests failed: 5 Run - $ ./tests.sh --help + $ ./tests/tests.sh --help for more details. diff --git a/docs/HACKING.md b/docs/HACKING.md index 7dfc497..08ddac2 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -43,5 +43,5 @@ function test_something() { `basic` is one of the directory trees generated for test cases; others include `links`, `loops`, `deep`, and `rainbow`. -Run `./tests.sh test_something --update` to generate the reference snapshot (and don't forget to `git add` it). +Run `./tests/tests.sh test_something --update` to generate the reference snapshot (and don't forget to `git add` it). Finally, add the test case to one of the arrays `posix_tests`, `bsd_tests`, `gnu_tests`, or `bfs_tests`, depending on which `find` implementations it should be compatible with. diff --git a/docs/USAGE.md b/docs/USAGE.md index 9f76f16..e2cff44 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -13,7 +13,6 @@ $ bfs ./completions ./docs ./src -./tests.sh ./tests ./completions/bfs.bash ./completions/bfs.zsh @@ -81,11 +80,11 @@ There are other operators like `-or`: ```console $ bfs -name '*.md' -or -name '*.sh' ./README.md -./tests.sh ./tests/find-color.sh ./tests/ls-color.sh ./tests/remove-sibling.sh ./tests/sort-args.sh +./tests/tests.sh ./docs/CHANGELOG.md ./docs/HACKING.md ./docs/BUILDING.md diff --git a/tests.sh b/tests/tests.sh index 52507a0..434e058 100755 --- a/tests.sh +++ b/tests/tests.sh @@ -86,7 +86,7 @@ Usage: ${GRN}$0${RST} [${BLU}--bfs${RST}=${MAG}path/to/bfs${RST}] [${BLU}--posix $pad [${BLD}test_*${RST} [${BLD}test_*${RST} ...]] ${BLU}--bfs${RST}=${MAG}path/to/bfs${RST} - Set the path to the bfs executable to test (default: ${MAG}./bfs${RST}) + Set the path to the bfs executable to test (default: ${MAG}./bin/bfs${RST}) ${BLU}--posix${RST}, ${BLU}--bsd${RST}, ${BLU}--gnu${RST}, ${BLU}--all${RST} Choose which test cases to run (default: ${BLU}--all${RST}) @@ -896,16 +896,14 @@ function _realpath() { ) } -ROOT=$(dirname -- "${BASH_SOURCE[0]}") +TESTS=$(_realpath "$(dirname -- "${BASH_SOURCE[0]}")") +BIN=$(_realpath "$TESTS/../bin") # Try to resolve the path to $BFS before we cd, while also supporting -# --bfs="./bfs -S ids" -read -a BFS <<<"${BFS:-$ROOT/bfs}" +# --bfs="./bin/bfs -S ids" +read -a BFS <<<"${BFS:-$BIN/bfs}" BFS[0]=$(_realpath "$(command -v "${BFS[0]}")") -BUILD=$(_realpath "$ROOT/build") -TESTS=$(_realpath "$ROOT/tests") - # The temporary directory that will hold our test data TMP=$(mktemp -d "${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX) chown "$(id -u):$(id -g)" "$TMP" @@ -1076,7 +1074,7 @@ function make_rainbow() { # TODO: block ln -s /dev/null "$1/chardev_link" ln -s nowhere "$1/broken" - "$BUILD/tests/mksock" "$1/socket" + "$BIN/tests/mksock" "$1/socket" touchp "$1"/s{u,g,ug}id chmod u+s "$1"/su{,g}id chmod g+s "$1"/s{u,}gid |