Skip to content

Commit

Permalink
Implement issue #62: search for ADR dir in parents of current
Browse files Browse the repository at this point in the history
directory.
  • Loading branch information
npryce committed Jul 25, 2018
1 parent db4185e commit b47d383
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 12 deletions.
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
TESTS:=$(wildcard tests/*.sh)
SRC:=$(wildcard src/*)

check: $(TESTS:tests/%.sh=build/tests/%.diff)
# Run tests outside the project directory so that they cannot interfere with the project's
# own ADR directory
BUILDDIR:=/tmp/adr-tools-build

check: $(TESTS:tests/%.sh=$(BUILDDIR)/tests/%.diff)
@echo SUCCESS

build/tests/%.diff: build/tests/%.output tests/%.expected
$(BUILDDIR)/tests/%.diff: $(BUILDDIR)/tests/%.output tests/%.expected
@diff --side-by-side $^ > $@ || ! cat $@

build/tests/%.output: tests/%.sh tests/%.expected $(SRC)
$(BUILDDIR)/tests/%.output: tests/%.sh tests/%.expected $(SRC)
@echo TEST: $*
@rm -rf $(dir $@)/$*
@mkdir -p $(dir $@)/$*
Expand All @@ -21,8 +25,11 @@ build/tests/%.output: tests/%.sh tests/%.expected $(SRC)
/bin/sh -v $(abspath $<) > $(abspath $@) 2>&1) || ! cat $@

clean:
rm -rf build/
rm -rf /tmp/adr-tools-build

show-%:
@echo "$* ($(flavor $*)) = $($*)"

.PHONY: all clean
.PRECIOUS: build/tests/%.output
.PRECIOUS: $(BUILDDIR)/tests/%.output
.DELETE_ON_ERROR:
2 changes: 1 addition & 1 deletion approve
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test="${1:?test}"

test_name=$(basename $test | sed 's/\..*//')

cp -v build/tests/$test_name.output tests/$test_name.expected
cp -v /tmp/adr-tools-build/tests/$test_name.output tests/$test_name.expected
32 changes: 26 additions & 6 deletions src/_adr_dir
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@
set -e
eval "$($(dirname $0)/adr-config)"

if [ -f .adr-dir ]
then
cat .adr-dir
else
echo doc/adr
fi
reldir=.

function mkrel() {
local d=$reldir/$1
echo ${d#./}
}

function absdir() {
(cd $(dirname $1) && pwd -P)
}

while [ $(absdir $reldir) != / ]
do
if [ -f $(mkrel .adr-dir) ]
then
mkrel $(cat $(mkrel .adr-dir))
exit
elif [ -d $(mkrel doc/adr) ]
then
mkrel doc/adr
exit
else
reldir=$reldir/..
fi
done
echo doc/adr
13 changes: 13 additions & 0 deletions tests/search-for-adr-dir.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
adr new First Record
doc/adr/0001-first-record.md
mkdir subdir
cd subdir
adr new Second Record
../doc/adr/0002-second-record.md
adr list
../doc/adr/0001-first-record.md
../doc/adr/0002-second-record.md
cd ..
adr list
doc/adr/0001-first-record.md
doc/adr/0002-second-record.md
7 changes: 7 additions & 0 deletions tests/search-for-adr-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
adr new First Record
mkdir subdir
cd subdir
adr new Second Record
adr list
cd ..
adr list
17 changes: 17 additions & 0 deletions tests/search-for-custom-adr-dir.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
adr init architecture-log
architecture-log/0001-record-architecture-decisions.md
adr new First Record
architecture-log/0002-first-record.md
mkdir subdir
cd subdir
adr new Second Record
../architecture-log/0003-second-record.md
adr list
../architecture-log/0001-record-architecture-decisions.md
../architecture-log/0002-first-record.md
../architecture-log/0003-second-record.md
cd ..
adr list
architecture-log/0001-record-architecture-decisions.md
architecture-log/0002-first-record.md
architecture-log/0003-second-record.md
8 changes: 8 additions & 0 deletions tests/search-for-custom-adr-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
adr init architecture-log
adr new First Record
mkdir subdir
cd subdir
adr new Second Record
adr list
cd ..
adr list

0 comments on commit b47d383

Please sign in to comment.