aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tools/test-project.sh
blob: 57026187e70b2c8e97dba764db295d624c4d0a13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# desktop-assistant tool check: project.sh against a scratch projects dir.
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# test-project.sh: projects go to a throwaway PROJECTS_DIR and KITTY=true,
# so no tab opens. Commits are really signed: a cold PIN cache asks once.
# Prints "ok" or one FAIL line per broken case.

set -u
here=$(dirname "$0")
PROJECTS_DIR=$(mktemp -d)
KITTY=true
export PROJECTS_DIR KITTY
trap 'rm -rf "$PROJECTS_DIR"' EXIT
fail=0
check() { [ "$2" = "$3" ] || { echo "FAIL $1: got '$2', want '$3'"; fail=1; }; }
p=$PROJECTS_DIR/demo
year=$(date +%Y)

out=$("$here/project.sh" demo "" "A demo project." "")
case "$out" in
    "created $p (GPLv2 only), committed "*", opened claude in a kitty "*) ;;
    *) echo "FAIL output: $out"; fail=1 ;;
esac
check "files" "$(cd "$p" && ls)" "$(printf '%s\n' AGENTS.md CLAUDE.md LICENSE README.md)"
check "signed" "$(git -C "$p" log --format=%G?)" "G"
check "branch" "$(git -C "$p" branch --show-current)" "master"
check "clean" "$(git -C "$p" status --porcelain)" ""
cmp -s "$p/LICENSE" "$here/licenses/gpl-2.0.txt"; check "license text" "$?" "0"
check "claude" "$(tail -1 "$p/CLAUDE.md")" "@AGENTS.md"
grep -qF '`demo`: A demo project.' "$p/AGENTS.md"; check "agents" "$?" "0"
grep -qF 'GPLv2 only. See [LICENSE]' "$p/README.md"; check "readme license" "$?" "0"
grep -qF '## Development Approach' "$p/README.md"; check "readme ai" "$?" "0"

out=$("$here/project.sh" m mit "MIT one." opencode)
case "$out" in *", opened opencode in a kitty "*) ;; *) echo "FAIL opencode: $out"; fail=1 ;; esac
check "mit" "$(grep -c "Copyright (c) $year Danilo M. <danix@danix.xyz>" "$PROJECTS_DIR/m/LICENSE")" "1"

for bad in Foo ../x "" .x; do
    "$here/project.sh" "$bad" "" "x." >/dev/null 2>&1; check "name '$bad'" "$?" "1"
done
"$here/project.sh" demo "" "x." >/dev/null 2>&1; check "exists" "$?" "1"
"$here/project.sh" n bsd "x." >/dev/null 2>&1; check "license" "$?" "1"
"$here/project.sh" n "" "" >/dev/null 2>&1; check "no description" "$?" "1"
"$here/project.sh" n "" "x." vim >/dev/null 2>&1; check "agent" "$?" "1"
check "nothing else made" "$(ls "$PROJECTS_DIR" | tr '\n' ' ')" "demo m "
[ $fail = 0 ] && echo "ok"
exit $fail