diff options
| author | Phillip Lord <phillip.lord@russet.org.uk> | 2019-06-16 20:21:31 +0100 |
|---|---|---|
| committer | Phillip Lord <phillip.lord@russet.org.uk> | 2019-06-16 20:21:31 +0100 |
| commit | 50885fbeea8a282dc027b03b19097de3c6dabd18 (patch) | |
| tree | 68462f789bb9e339c48d061dad578f6569a3b879 | |
| parent | a923ba2c90ebb5e7fd66b29f6a3af7fd12b6b9f4 (diff) | |
| download | org-drill-50885fbeea8a282dc027b03b19097de3c6dabd18.tar.gz org-drill-50885fbeea8a282dc027b03b19097de3c6dabd18.zip | |
Refactor robot testing to allow multiple tests
| -rw-r--r-- | org-drill.el | 9 | ||||
| -rw-r--r-- | robot/basic-run.el | 50 | ||||
| -rwxr-xr-x | robot/basic-run.sh | 5 | ||||
| -rw-r--r-- | robot/robot.el | 60 | ||||
| -rw-r--r-- | robot/robot.sh | 20 |
5 files changed, 89 insertions, 55 deletions
diff --git a/org-drill.el b/org-drill.el index 694d51b..3c55062 100644 --- a/org-drill.el +++ b/org-drill.el @@ -652,6 +652,11 @@ for review unless they were already reviewed in the recent past?" (defvar org-drill-current-session nil) (defvar org-drill-last-session nil) +(defvar org-drill-cards-in-this-emacs 0 + "The total number of cards displayed in this Emacs invocation. + +This variable is not functionally important, but is used for + debugging.") (defvar org-drill-scheduling-properties '("LEARN_DATA" "DRILL_LAST_INTERVAL" "DRILL_REPEATS_SINCE_FAIL" @@ -2578,6 +2583,7 @@ See `org-drill' for more details." (mapc (apply-partially 'org-drill-card-tag-caller 3) (org-get-tags)) + (cl-incf org-drill-cards-in-this-emacs) (org-remove-latex-fragment-image-overlays) rtn)))))) @@ -3056,7 +3062,8 @@ work correctly with older versions of org mode. Your org mode version (%s) appea (let ((session (if resume-p org-drill-last-session - (org-drill-session))) + (setq org-drill-last-session + (org-drill-session)))) (end-pos nil) (cnt 0)) (cl-block org-drill diff --git a/robot/basic-run.el b/robot/basic-run.el index 1469fef..8e853e3 100644 --- a/robot/basic-run.el +++ b/robot/basic-run.el @@ -1,50 +1,4 @@ -;; Shutup -(setq make-backup-files nil) -(setq auto-save-default nil) - -(setq top-dir default-directory) - -;; Clean up -(delete-file (concat top-dir "robot/failure.txt")) -(delete-file (concat top-dir "robot/messages.txt")) - -(set-frame-name "emacs-bot") - -(setq debug-on-error t) -(setq debug-on-quit t) - -(defun die () - (interactive) - (kill-emacs) - ) - -(defun dump-buffer (buffer file) - (save-excursion - (when (get-buffer buffer) - (set-buffer buffer) - (write-region (point-min) (point-max) - (concat top-dir "robot/" file) - nil 'dont-display-wrote-file-message - )))) - -(add-hook 'debugger-mode-hook - 'org-drill-launcher-dump-in-a-bit) - -(defun org-drill-launcher-dump-in-a-bit () - (run-with-timer 1 nil #'org-drill-launcher-dump)) - -(defun org-drill-dump-messages () - (dump-buffer "*Messages*" "messages.txt")) - -(run-with-timer 1 1 #'org-drill-dump-messages) - - -(defun org-drill-launcher-dump () - (dump-buffer "*Backtrace*" "failure.txt") - (dump-buffer "*Messages*" "messages.txt") - (kill-emacs -1) - ) - +(load-file "robot/robot.el") (load-file "org-drill.el") (defun org-drill-do-drill () @@ -62,3 +16,5 @@ (setq org-drill-presentation-prompt-with-typing t) (org-drill-do-drill) + +(robot-check-cards-seen-and-die 6) diff --git a/robot/basic-run.sh b/robot/basic-run.sh index 5f68cab..d92172d 100755 --- a/robot/basic-run.sh +++ b/robot/basic-run.sh @@ -31,9 +31,6 @@ source $this_dir/robot.sh launch_emacs $this_dir/basic-run.el -#small_sleep=5 -#big_sleep=10 - { sleep 2 find_bot @@ -44,6 +41,6 @@ launch_emacs $this_dir/basic-run.el ## Run once with presentation-prompt-with-typing run_drill - kill_emacs + wait_emacs } || cat robot/failure.txt $EMACS -Q -l $1 & diff --git a/robot/robot.el b/robot/robot.el new file mode 100644 index 0000000..43f31da --- /dev/null +++ b/robot/robot.el @@ -0,0 +1,60 @@ +;; Shutup +(setq make-backup-files nil) +(setq auto-save-default nil) + +(setq top-dir default-directory) + +(set-frame-name "emacs-bot") + +(setq debug-on-error t) +(setq debug-on-quit t) + +(defun clean (file) + (delete-file (concat top-dir "robot/" file))) + +;; Clean up +(clean "failure.txt") +(clean "messages.txt") + +(defun die () + (interactive) + (kill-emacs)) + +(defun dump-buffer (buffer file) + (save-excursion + (when (get-buffer buffer) + (set-buffer buffer) + (write-region (point-min) (point-max) + (concat top-dir "robot/" file) + nil 'dont-display-wrote-file-message + )))) + + +(add-hook 'debugger-mode-hook + 'robot-dump-in-a-bit) + +(defun robot-dump-in-a-bit () + (run-with-timer 1 nil #'robot-dump)) + +(defun robot-dump () + (dump-buffer "*Backtrace*" "failure.txt") + (dump-buffer "*Messages*" "messages.txt") + (kill-emacs -1)) + +(defun robot-dump-messages () + (dump-buffer "*Messages*" "messages.txt")) + +(run-with-timer 1 1 #'robot-dump-messages) + +(defun robot-check-cards-seen-and-die (n) + (if (= n org-drill-cards-in-this-emacs) + (progn + (princ + (format "Succeeded: Saw %s cards as expected\n" n) + 'external-debugging-output) + (kill-emacs 0)) + (princ + (format "Failed: Saw %s cards, expecting %s\n" + org-drill-cards-in-this-emacs n) + 'external-debugging-output) + (kill-emacs -1))) diff --git a/robot/robot.sh b/robot/robot.sh index e013308..022b567 100644 --- a/robot/robot.sh +++ b/robot/robot.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + ## call find_bot to init this window_id= @@ -8,6 +10,8 @@ window_id= small_sleep=0.25 big_sleep=1 +emacs_process_pid= + function sleep_small { sleep $small_sleep } @@ -26,6 +30,7 @@ function send_answer { function launch_emacs { echo Launching $EMACS -Q -l $1 & $EMACS -Q -l $1 & + emacs_process_pid=$! } function kill_emacs { @@ -34,16 +39,25 @@ function kill_emacs { retn } +function xdo { + xdotool $1 --window $window_id $2 || { + echo "Failed command: $1, $2";exit 1 + } +} function key { - xdotool key --window $window_id $1 + xdo key $1 } function command { - xdotool type --window $window_id $1 + xdo type $1 } function retn { - xdotool key --window $window_id Return + key Return +} + +function wait_emacs { + wait $emacs_process_pid } function find_bot { |
