Refactor robot testing
Phillip Lord
4 years ago
6 | 6 | EMACS_ENV=EMACS=$(EMACS) |
7 | 7 | endif |
8 | 8 | |
9 | all: | |
9 | all: robot-and-test | |
10 | 10 | |
11 | 11 | install: |
12 | 12 | $(EMACS_ENV) $(CASK) install |
13 | 13 | |
14 | 14 | test: install just-test |
15 | 15 | |
16 | robot-and-test: robot-test just-test | |
16 | robot-and-test: basic-robot-test just-test | |
17 | 17 | |
18 | 18 | just-test: |
19 | 19 | $(EMACS_ENV) $(CASK) emacs --batch -q \ |
34 | 34 | $(MAKE) test-git DOCKER_TAG=25.3 |
35 | 35 | $(MAKE) test-cp DOCKER_TAG=25.3 |
36 | 36 | |
37 | robot-test: | |
37 | basic-robot-test: | |
38 | 38 | $(CASK) clean-elc |
39 | $(EMACS_ENV) ./robot/robot-test.sh | |
39 | $(EMACS_ENV) ./robot/basic-run.sh | |
40 | 40 | |
41 | 41 | .PHONY: test |
0 | ;; Shutup | |
1 | (setq make-backup-files nil) | |
2 | (setq auto-save-default nil) | |
3 | ||
4 | (setq top-dir default-directory) | |
5 | ||
6 | ;; Clean up | |
7 | (delete-file (concat top-dir "robot/failure.txt")) | |
8 | (delete-file (concat top-dir "robot/messages.txt")) | |
9 | ||
10 | (set-frame-name "emacs-bot") | |
11 | ||
12 | (setq debug-on-error t) | |
13 | (setq debug-on-quit t) | |
14 | ||
15 | (defun die () | |
16 | (interactive) | |
17 | (kill-emacs) | |
18 | ) | |
19 | ||
20 | (defun dump-buffer (buffer file) | |
21 | (save-excursion | |
22 | (when (get-buffer buffer) | |
23 | (set-buffer buffer) | |
24 | (write-region (point-min) (point-max) | |
25 | (concat top-dir "robot/" file) | |
26 | nil 'dont-display-wrote-file-message | |
27 | )))) | |
28 | ||
29 | (add-hook 'debugger-mode-hook | |
30 | 'org-drill-launcher-dump-in-a-bit) | |
31 | ||
32 | (defun org-drill-launcher-dump-in-a-bit () | |
33 | (run-with-timer 1 nil #'org-drill-launcher-dump)) | |
34 | ||
35 | (defun org-drill-dump-messages () | |
36 | (dump-buffer "*Messages*" "messages.txt")) | |
37 | ||
38 | (run-with-timer 1 1 #'org-drill-dump-messages) | |
39 | ||
40 | ||
41 | (defun org-drill-launcher-dump () | |
42 | (dump-buffer "*Backtrace*" "failure.txt") | |
43 | (dump-buffer "*Messages*" "messages.txt") | |
44 | (kill-emacs -1) | |
45 | ) | |
46 | ||
47 | (load-file "org-drill.el") | |
48 | ||
49 | (defun org-drill-do-drill () | |
50 | (copy-file "robot/main-test.org" "robot/main-test-copy.org" t) | |
51 | (find-file "robot/main-test-copy.org") | |
52 | ||
53 | (org-drill) | |
54 | (set-buffer-modified-p nil) | |
55 | (kill-buffer)) | |
56 | ||
57 | (org-drill-do-drill) | |
58 | ||
59 | (message "First drill complete") | |
60 | ||
61 | (setq org-drill-presentation-prompt-with-typing t) | |
62 | ||
63 | (org-drill-do-drill) |
0 | #!/bin/bash | |
1 | ||
2 | set -e | |
3 | ||
4 | function run_drill { | |
5 | ## Org-drill should be running at this point, so give three answers | |
6 | ## with a score of file | |
7 | sleep_big | |
8 | ||
9 | echo answer one | |
10 | send_answer | |
11 | ||
12 | echo answer two | |
13 | send_answer | |
14 | ||
15 | echo answer three | |
16 | send_answer | |
17 | ||
18 | ## Press any key to continue | |
19 | echo press any key to continue | |
20 | retn | |
21 | sleep_small | |
22 | ||
23 | echo Save file | |
24 | key y | |
25 | } | |
26 | ||
27 | this_dir="$(dirname "$0")" | |
28 | source $this_dir/robot.sh | |
29 | ||
30 | ||
31 | launch_emacs $this_dir/basic-run.el | |
32 | ||
33 | bsmall_sleep=5 | |
34 | big_sleep=10 | |
35 | ||
36 | { | |
37 | sleep 2 | |
38 | find_bot | |
39 | ||
40 | ## Run once with default options | |
41 | run_drill | |
42 | ||
43 | ## Run once with presentation-prompt-with-typing | |
44 | run_drill | |
45 | ||
46 | # kill_emacs | |
47 | } || cat robot/failure.txt | |
48 | $EMACS -Q -l $1 & |
0 | ;; Shutup | |
1 | (setq make-backup-files nil) | |
2 | (setq auto-save-default nil) | |
3 | ||
4 | (setq top-dir default-directory) | |
5 | ||
6 | ;; Clean up | |
7 | (delete-file (concat top-dir "robot/failure.txt")) | |
8 | (delete-file (concat top-dir "robot/messages.txt")) | |
9 | ||
10 | (set-frame-name "emacs-bot") | |
11 | ||
12 | (setq debug-on-error t) | |
13 | (setq debug-on-quit t) | |
14 | ||
15 | (defun dump-buffer (buffer file) | |
16 | (save-excursion | |
17 | (when (get-buffer buffer) | |
18 | (set-buffer buffer) | |
19 | (write-region (point-min) (point-max) | |
20 | (concat top-dir "robot/" file) | |
21 | nil 'dont-display-wrote-file-message | |
22 | )))) | |
23 | ||
24 | (add-hook 'debugger-mode-hook | |
25 | 'org-drill-launcher-dump-in-a-bit) | |
26 | ||
27 | (defun org-drill-launcher-dump-in-a-bit () | |
28 | (run-with-timer 1 nil #'org-drill-launcher-dump)) | |
29 | ||
30 | (defun org-drill-dump-messages () | |
31 | (dump-buffer "*Messages*" "messages.txt")) | |
32 | ||
33 | (run-with-timer 1 1 #'org-drill-dump-messages) | |
34 | ||
35 | ||
36 | (defun org-drill-launcher-dump () | |
37 | (dump-buffer "*Backtrace*" "failure.txt") | |
38 | (dump-buffer "*Messages*" "messages.txt") | |
39 | (kill-emacs -1)) | |
40 | ||
41 | (load-file "org-drill.el") | |
42 | ||
43 | (defun org-drill-do-drill () | |
44 | (copy-file "robot/main-test.org" "robot/main-test-copy.org" t) | |
45 | (find-file "robot/main-test-copy.org") | |
46 | ||
47 | (org-drill) | |
48 | (set-buffer-modified-p nil) | |
49 | (kill-buffer)) | |
50 | ||
51 | (org-drill-do-drill) | |
52 | ||
53 | (message "First drill complete") | |
54 | ||
55 | (setq org-drill-presentation-prompt-with-typing t) | |
56 | ||
57 | (org-drill-do-drill) |
0 | #!/bin/bash | |
1 | ||
2 | set -e | |
3 | ||
4 | function run_drill { | |
5 | ## Org-drill should be running at this point, so give three answers | |
6 | ## with a score of file | |
7 | sleep 1 | |
8 | echo answer one | |
9 | #xdotool type --window $window_id answer | |
10 | xdotool key --window $window_id Return | |
11 | sleep 0.25 | |
12 | xdotool key --window $window_id 5 | |
13 | sleep 0.25 | |
14 | ||
15 | ||
16 | echo answer two | |
17 | #xdotool type --window $window_id answer | |
18 | xdotool key --window $window_id Return | |
19 | sleep 0.25 | |
20 | xdotool key --window $window_id 5 | |
21 | sleep 0.25 | |
22 | ||
23 | echo answer three | |
24 | #xdotool type --window $window_id answer | |
25 | xdotool key --window $window_id Return | |
26 | sleep 0.25 | |
27 | xdotool key --window $window_id 5 | |
28 | sleep 0.25 | |
29 | ||
30 | ## Press any key to continue | |
31 | echo press any key to continue | |
32 | xdotool key --window $window_id Return | |
33 | sleep 0.25 | |
34 | ||
35 | echo Save file | |
36 | xdotool key --window $window_id y | |
37 | } | |
38 | ||
39 | function kill_emacs { | |
40 | echo Goodnight Emacs | |
41 | xdotool key --window $window_id alt+x | |
42 | xdotool type --window $window_id kill-emacs | |
43 | xdotool key --window $window_id KP_Enter | |
44 | } | |
45 | ||
46 | $EMACS -Q -l ./robot/org-drill-launch.el & | |
47 | ||
48 | { | |
49 | sleep 2 | |
50 | ||
51 | window_id=`xdotool search --name "emacs-bot"` | |
52 | if [ -z "$window_id" ] | |
53 | then | |
54 | echo "Could not find window ID for Emacs-bot" | |
55 | exit 1 | |
56 | fi | |
57 | ||
58 | ## Run once with default options | |
59 | run_drill | |
60 | ||
61 | ## Run once with presentation-prompt-with-typing | |
62 | run_drill | |
63 | ||
64 | kill_emacs | |
65 | } || cat robot/failure.txt |
0 | #!/bin/bash | |
1 | ||
2 | ## call find_bot to init this | |
3 | window_id= | |
4 | ||
5 | ## This is the small sleep between key presses. Change for debugging | |
6 | ## when you are not sure what is happening | |
7 | small_sleep=0.25 | |
8 | big_sleep=1 | |
9 | ||
10 | function sleep_small { | |
11 | sleep $small_sleep | |
12 | } | |
13 | ||
14 | function sleep_big { | |
15 | sleep $big_sleep | |
16 | } | |
17 | ||
18 | function send_answer { | |
19 | retn | |
20 | sleep_small | |
21 | key 5 | |
22 | sleep_small | |
23 | } | |
24 | ||
25 | function launch_emacs { | |
26 | echo Launching $EMACS -Q -l $1 & | |
27 | $EMACS -Q -l $1 & | |
28 | } | |
29 | ||
30 | function kill_emacs { | |
31 | key alt+x | |
32 | command kill-emacs | |
33 | retn | |
34 | } | |
35 | ||
36 | function key { | |
37 | xdotool key --window $window_id $1 | |
38 | } | |
39 | ||
40 | function command { | |
41 | xdotool type --window $window_id $1 | |
42 | } | |
43 | ||
44 | function retn { | |
45 | xdotool key --window $window_id Return | |
46 | } | |
47 | ||
48 | function find_bot { | |
49 | window_id=`xdotool search --name "emacs-bot"` | |
50 | if [ -z "$window_id" ] | |
51 | then | |
52 | echo "Could not find window ID for Emacs-bot" | |
53 | exit 1 | |
54 | fi | |
55 | } |