-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.sh
executable file
·84 lines (61 loc) · 2.03 KB
/
test.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# A basic non-hermetic test to validate changes and demonstrate output.
set -e # Exit on error.
test -f ./ocd-install.sh || \
(echo 'Run this in the same dir as ocd-install.sh' && exit 1)
# Use a tmpdir as the homedir for testing.
FAKE_HOME="$(mktemp -d)"
OCD_HOME="$FAKE_HOME" # For safety because I rm -rf $FAKE_HOME below.
OCD_BARE="${OCD_HOME}/.ocd"
cleanup() { rm -rf "$FAKE_HOME"; }
trap cleanup EXIT SIGINT SIGTERM
OCD="git --git-dir=$OCD_BARE --work-tree=$FAKE_HOME"
EXAMPLE_FILE="example.md"
# Write the initial part of example.md to show how the script is invoked.
cat > "$EXAMPLE_FILE" << 'END'
# Example: `ocd-install.sh`
The following shows console output from `ocd-install.sh` (via
the [test script](./test.sh)) to demonstrate what the setup looks like:
```
$ ./ocd-install.sh -r https://github.com/mathiasbynens/dotfiles.git -c -h -g
END
# Run ocd-install.sh with flags, capturing output in example.md.
{
./ocd-install.sh -r "https://github.com/mathiasbynens/dotfiles.git" \
-c -h -g -B "$OCD_BARE" -H "$OCD_HOME"
echo '```';
} &>> "$EXAMPLE_FILE"
cat >> "$EXAMPLE_FILE" << 'END'
Running `ocd status` after modifying tracked file `.gitconfig`:
```
# [...modifying config here...]
$ ocd status
END
echo "# Hello from $0" >> $OCD_HOME/.gitconfig
{
$OCD status;
cat << END
\`\`\`
And then \`ocd add\` and \`ocd commit\`:
\`\`\`
$ ocd add $OCD_HOME/.gitconfig
$ ocd commit -m 'Testing OCD'
END
$OCD add "$OCD_HOME/.gitconfig";
$OCD commit -m 'Testing OCD';
echo '```';
} >> "$EXAMPLE_FILE"
echo "OK: ocd-install.sh"
# Spot-check .gitignore_ocd for a known SSH rule.
if ! grep -q '^.ssh/id_' "$FAKE_HOME/.gitignore_ocd"; then
echo "[!] .gitignore_ocd is missing some rules." && exit 1
else
echo "OK: .gitignore_ocd"
fi
# Confirm the pre-commit hook is in place.
if [ ! -f "$OCD_BARE/hooks/pre-commit" ]; then
echo "[!] Missing pre-commit hook at $OCD_BARE/hooks/pre-commit" && exit 1
else
echo "OK: $OCD_BARE/hooks/pre-commit"
fi
echo -e "\n[*] Don't forget to add example.md to your commit!"