-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathert-tests.sh
executable file
·169 lines (128 loc) · 3.45 KB
/
ert-tests.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# Copyright (c) 2022-2024 Gonzalo Larumbe
# All rights reserved.
# * Utils
run_elisp_cmd() {
local CMD=$1
local PACKAGE=$2
local PKG_MANAGER=$3
args=(-Q -nw -batch
-L "${TEST_HDL_PATH}"
-L test/src
-l ert
-l "${PACKAGE}"-test-setup-"${PKG_MANAGER}"
-l "${PACKAGE}"-test
--eval "$CMD")
emacs "${args[@]}"
}
run_tests () {
local RC=
local CMD=
local PACKAGE=$1
local PKG_MANAGER=$2
local SELECTOR=$3
if [[ -z "$PACKAGE" ]]; then
echo "run_tests: PACKAGE not provided"
exit 1
fi
if [[ -z "$PKG_MANAGER" ]]; then
echo "run_tests: PKG_MANAGER not provided"
exit 1
fi
echo "#######################"
echo "## Running ERT tests ##"
echo "#######################"
echo ""
if [[ -n "$SELECTOR" ]]; then
if [[ "$SELECTOR" == "t" ]]; then # Don't double-quote t symbol
CMD="(ert-run-tests-batch-and-exit t)"
else
CMD="(ert-run-tests-batch-and-exit \"$SELECTOR\")"
fi
else
CMD="(ert-run-tests-batch-and-exit)"
fi
run_elisp_cmd "$CMD" "$PACKAGE" "$PKG_MANAGER"
RC=$?
echo "Exiting with return code $RC"
return $RC
}
check_package_el() {
local RC=
local PACKAGE=$1
args=(-Q -nw -batch
-L "${TEST_HDL_PATH}"
-L test/src
-l ert
-l "${PACKAGE}"-test-setup-package
-l "${PACKAGE}"-test
-l "${PACKAGE}"-test-setup-package-test
--eval "(${PACKAGE}-test-setup-package-test-basic)")
emacs "${args[@]}"
RC=$?
echo "Exiting with return code $RC"
return $RC
}
clean() {
PACKAGE=$1
local STRAIGHT_DIR="../../build/$PACKAGE"
echo "Removing .elc files"
find . -name "*.elc" -exec rm -v {} \;
if [[ -d "$STRAIGHT_DIR" ]]; then
find "$STRAIGHT_DIR" -name "*.elc" -exec rm -v {} \;
fi
echo ""
}
compile() {
local CMD="(test-hdl-compile-dir \"$PWD\")"
local PACKAGE=$1
echo "###############"
echo "## Compiling ##"
echo "###############"
echo ""
run_elisp_cmd "$CMD" "$PACKAGE" "straight"
echo ""
}
recompile() {
local PACKAGE=$1
clean "$PACKAGE"
compile "$PACKAGE"
}
recompile_run () {
local PACKAGE=$1
local SELECTOR=$2
recompile "$PACKAGE"
run_tests "$PACKAGE" "straight" "$SELECTOR"
}
gen_expected () {
local CMD=
local PACKAGE=$1
local SELECTOR=$2
if [[ -z "$SELECTOR" ]]; then
CMD="(${PACKAGE}-test-gen-expected-files)"
else
CMD="(${PACKAGE}-test-${SELECTOR}-gen-expected-files)"
fi
run_elisp_cmd "$CMD" "$PACKAGE" "straight"
}
git_reset_to_latest_tag () {
# Abort if there are uncommitted changes
if [[ -n "$(git status --porcelain)" ]]; then
echo "There are uncommitted changes:"
git status
exit 1
else
# Get new tags from remote
git fetch --tags
# Get latest tag name
latestTag=$(git describe --tags $(git rev-list --tags --max-count=1))
[[ -z "$latestTag" ]] && { echo "Could not retrieve latest tag"; exit 1;}
# Create temp branch to avoid issues with main in case there are fatals/errors
git checkout -b ci/$latestTag
# Point main rapo to latest tag and update its submodules
git reset --hard --recurse-submodules $latestTag
echo "Current branch: $(git log --format='%d' -1 HEAD)"
fi
}
# Main
"$@"