-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup
executable file
·93 lines (79 loc) · 1.72 KB
/
setup
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
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# invoke this script from your projects root directory
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# pass "undo" as a script arg to undo most of the setup actions
UNDO_SETUP="$1"
undo() {
[ "$UNDO_SETUP" == "undo" ]
}
restore() {
local file="$1"
rm -f "$file"
git checkout -- "$file" 2>/dev/null
}
gitignore() {
local file="$1"
grep -q "^${file}$" .gitignore 2>/dev/null || echo "$file" >> .gitignore
}
remove_from_gitignore() {
local file="$1"
local escaped_filename="$(echo "$file" | sed "s,/,\\\/,g")"
sed -i"" "/^${escaped_filename}$/d" .gitignore
}
add_files_to_gitignore() {
if ! undo; then
gitignore "run_tests"
gitignore "tests/run_tests_in_isolation"
gitignore "tests/helpers/helpers.sh"
else
remove_from_gitignore "run_tests"
remove_from_gitignore "tests/run_tests_in_isolation"
remove_from_gitignore "tests/helpers/helpers.sh"
fi
}
symlink_user_test_runner() {
local file="run_tests"
if ! undo; then
ln -sf "lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
create_directory_for_tests() {
if ! undo; then
mkdir -p tests/helpers/
fi
}
symlink_internal_test_runner() {
local file="tests/run_tests_in_isolation"
if ! undo; then
ln -sf "../lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
symlink_test_helpers() {
local file="tests/helpers/helpers.sh"
if ! undo; then
ln -sf "../../lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
copy_travis_yml() {
local file=".travis.yml"
if ! undo; then
cp "lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
main() {
add_files_to_gitignore
symlink_user_test_runner
create_directory_for_tests
symlink_internal_test_runner
symlink_test_helpers
copy_travis_yml
}
main