-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest
More file actions
executable file
·166 lines (149 loc) · 4.58 KB
/
test
File metadata and controls
executable file
·166 lines (149 loc) · 4.58 KB
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
#!/bin/bash
# Run flywrite ERT tests in batch mode.
# Stop on errors
set -Eeuo pipefail
# Run from project directory
cd "$(dirname "$0")"
# Clean up automatically generated files on exit
cleanup() {
rm -f ./*.elc flywrite-autoloads.el
}
trap cleanup EXIT
# Emacs Lisp source files
EL_FILE_PACKAGE=flywrite.el
EL_FILES_TESTS=(
lint-nesting.el
test-flywrite.el
test-flywrite-prompt.el
)
EL_FILES=("$EL_FILE_PACKAGE" "${EL_FILES_TESTS[@]}")
# Byte-compile check
echo "Byte-compile check"
emacs \
-Q --batch \
--eval "(setq byte-compile-error-on-warn t)" \
--eval "(push default-directory load-path)" \
-f batch-byte-compile \
"${EL_FILES[@]}"
# Lint: elint
ELINT_INIT='(progn
(setq inhibit-message t)
(require (quote elint))
(push default-directory load-path)
(dolist (f command-line-args-left)
(elint-file f))
(setq command-line-args-left nil)
(with-current-buffer "*Elint*"
(let ((output (buffer-string)))
(unless (string= output "")
(princ output)
(kill-emacs 1)))))'
echo "Lint: elint"
emacs \
-Q --batch \
--eval "$ELINT_INIT" \
"${EL_FILES[@]}"
# Lint: elisp-lint
# Install from MELPA, disable checks run separately, includes checkdoc
ELISP_LINT_INIT='(progn
(require (quote package))
(add-to-list (quote package-archives)
(quote ("melpa" . "https://melpa.org/packages/")) t)
(package-initialize)
(unless (package-installed-p (quote elisp-lint))
(package-refresh-contents)
(package-install (quote elisp-lint)))
(require (quote elisp-lint))
(push default-directory load-path))'
echo "Lint: elisp-lint"
emacs \
-Q --batch \
--eval "$ELISP_LINT_INIT" \
-f elisp-lint-files-batch \
"$EL_FILE_PACKAGE"
# Lint: elisp-lint
# Test and utility files: skip package-lint and checkdoc (not packages)
echo "Lint: elisp-lint (test/utility files)"
emacs \
-Q --batch \
--eval "$ELISP_LINT_INIT" \
-f elisp-lint-files-batch \
--no-package-lint \
--no-checkdoc \
"${EL_FILES_TESTS[@]}"
# Lint: package-lint
PACKAGE_LINT_INIT='(progn
(require (quote package))
(add-to-list (quote package-archives)
(quote ("melpa" . "https://melpa.org/packages/")) t)
(package-initialize)
(unless (package-installed-p (quote package-lint))
(package-refresh-contents)
(package-install (quote package-lint)))
(require (quote package-lint)))'
echo "Lint: package-lint"
emacs \
-Q --batch \
--eval "$PACKAGE_LINT_INIT" \
-f package-lint-batch-and-exit \
"$EL_FILE_PACKAGE"
# Lint: nesting depth (control-flow forms only, max depth 5)
echo "Lint: nesting depth"
emacs \
-Q --batch \
--eval '(setq lint-nesting-max-depth 5)' \
-l lint-nesting.el \
"${EL_FILES[@]}"
# Unit tests (filter expected flywrite log messages from stderr)
echo "Unit tests"
emacs \
-Q --batch \
-l flywrite.el \
-l test-flywrite.el \
-f ert-run-tests-batch-and-exit \
2>&1 | { grep -v '^flywrite:' >&2 || true; }
# Prompt regression tests (requires API key or cached responses)
echo "Prompt regression tests"
emacs \
-Q --batch \
-l flywrite.el \
-l test-flywrite-prompt.el \
-f ert-run-tests-batch-and-exit
# Check: README system prompt matches source
# The README "Replace a built-in prompt" example copies the academic prompt and
# adds extra rules. Use Emacs to parse the elisp strings from both files, then
# verify the README version starts with the source and is strictly longer.
echo "Check: README system prompt matches source"
FLYWRITE_SYSTEM_PROMPT=$(
emacs -Q --batch -l flywrite.el --eval '(princ flywrite-academic-prompt)'
)
if [ -z "${FLYWRITE_SYSTEM_PROMPT}" ]; then
echo "Error: failed to extract system prompt from flywrite.el" >&2
exit 1
fi
README_SYSTEM_PROMPT=$(
emacs -Q --batch --eval '
(with-temp-buffer
(insert-file-contents "README.md")
(while (re-search-forward "(setq flywrite-academic-prompt" nil t)
(goto-char (match-beginning 0))
(let ((form (read (current-buffer))))
(when (stringp (nth 2 form))
(princ (nth 2 form))))))'
)
if [ -z "${README_SYSTEM_PROMPT}" ]; then
echo "Error: failed to extract system prompt from README.md" >&2
exit 1
fi
# README prompt must start with the source prompt and be strictly longer
if [ "${README_SYSTEM_PROMPT}" = "${FLYWRITE_SYSTEM_PROMPT}" ]; then
echo "Error: README system prompt is identical to source (should be longer)" >&2
exit 1
fi
if [ "${README_SYSTEM_PROMPT#"${FLYWRITE_SYSTEM_PROMPT}"}" = "${README_SYSTEM_PROMPT}" ]; then
echo "Error: README system prompt does not start with flywrite.el prompt" >&2
exit 1
fi
echo "########################################"
echo "# $0 PASS"
echo "########################################"