From be851b9eb42faa3c096737daaab0afcbc8c5087e Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Sat, 15 Jun 2019 22:10:03 +0100 Subject: Refactor robot testing --- Makefile | 8 +++--- robot/basic-run.el | 64 +++++++++++++++++++++++++++++++++++++++++++++ robot/basic-run.sh | 49 +++++++++++++++++++++++++++++++++++ robot/org-drill-launch.el | 58 ----------------------------------------- robot/robot-test.sh | 66 ----------------------------------------------- robot/robot.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 128 deletions(-) create mode 100644 robot/basic-run.el create mode 100755 robot/basic-run.sh delete mode 100644 robot/org-drill-launch.el delete mode 100755 robot/robot-test.sh create mode 100644 robot/robot.sh diff --git a/Makefile b/Makefile index ea827e6..b5da638 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,14 @@ ifdef EMACS EMACS_ENV=EMACS=$(EMACS) endif -all: +all: robot-and-test install: $(EMACS_ENV) $(CASK) install test: install just-test -robot-and-test: robot-test just-test +robot-and-test: basic-robot-test just-test just-test: $(EMACS_ENV) $(CASK) emacs --batch -q \ @@ -35,8 +35,8 @@ docker-test: $(MAKE) test-git DOCKER_TAG=25.3 $(MAKE) test-cp DOCKER_TAG=25.3 -robot-test: +basic-robot-test: $(CASK) clean-elc - $(EMACS_ENV) ./robot/robot-test.sh + $(EMACS_ENV) ./robot/basic-run.sh .PHONY: test diff --git a/robot/basic-run.el b/robot/basic-run.el new file mode 100644 index 0000000..1469fef --- /dev/null +++ b/robot/basic-run.el @@ -0,0 +1,64 @@ +;; 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 "org-drill.el") + +(defun org-drill-do-drill () + (copy-file "robot/main-test.org" "robot/main-test-copy.org" t) + (find-file "robot/main-test-copy.org") + + (org-drill) + (set-buffer-modified-p nil) + (kill-buffer)) + +(org-drill-do-drill) + +(message "First drill complete") + +(setq org-drill-presentation-prompt-with-typing t) + +(org-drill-do-drill) diff --git a/robot/basic-run.sh b/robot/basic-run.sh new file mode 100755 index 0000000..497f157 --- /dev/null +++ b/robot/basic-run.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e + +function run_drill { + ## Org-drill should be running at this point, so give three answers + ## with a score of file + sleep_big + + echo answer one + send_answer + + echo answer two + send_answer + + echo answer three + send_answer + + ## Press any key to continue + echo press any key to continue + retn + sleep_small + + echo Save file + key y +} + +this_dir="$(dirname "$0")" +source $this_dir/robot.sh + + +launch_emacs $this_dir/basic-run.el + +bsmall_sleep=5 +big_sleep=10 + +{ + sleep 2 + find_bot + + ## Run once with default options + run_drill + + ## Run once with presentation-prompt-with-typing + run_drill + + # kill_emacs +} || cat robot/failure.txt + $EMACS -Q -l $1 & diff --git a/robot/org-drill-launch.el b/robot/org-drill-launch.el deleted file mode 100644 index 2de9219..0000000 --- a/robot/org-drill-launch.el +++ /dev/null @@ -1,58 +0,0 @@ -;; 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 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 "org-drill.el") - -(defun org-drill-do-drill () - (copy-file "robot/main-test.org" "robot/main-test-copy.org" t) - (find-file "robot/main-test-copy.org") - - (org-drill) - (set-buffer-modified-p nil) - (kill-buffer)) - -(org-drill-do-drill) - -(message "First drill complete") - -(setq org-drill-presentation-prompt-with-typing t) - -(org-drill-do-drill) diff --git a/robot/robot-test.sh b/robot/robot-test.sh deleted file mode 100755 index c27b94b..0000000 --- a/robot/robot-test.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -set -e - -function run_drill { - ## Org-drill should be running at this point, so give three answers - ## with a score of file - sleep 1 - echo answer one - #xdotool type --window $window_id answer - xdotool key --window $window_id Return - sleep 0.25 - xdotool key --window $window_id 5 - sleep 0.25 - - - echo answer two - #xdotool type --window $window_id answer - xdotool key --window $window_id Return - sleep 0.25 - xdotool key --window $window_id 5 - sleep 0.25 - - echo answer three - #xdotool type --window $window_id answer - xdotool key --window $window_id Return - sleep 0.25 - xdotool key --window $window_id 5 - sleep 0.25 - - ## Press any key to continue - echo press any key to continue - xdotool key --window $window_id Return - sleep 0.25 - - echo Save file - xdotool key --window $window_id y -} - -function kill_emacs { - echo Goodnight Emacs - xdotool key --window $window_id alt+x - xdotool type --window $window_id kill-emacs - xdotool key --window $window_id KP_Enter -} - -$EMACS -Q -l ./robot/org-drill-launch.el & - -{ - sleep 2 - - window_id=`xdotool search --name "emacs-bot"` - if [ -z "$window_id" ] - then - echo "Could not find window ID for Emacs-bot" - exit 1 - fi - - ## Run once with default options - run_drill - - ## Run once with presentation-prompt-with-typing - run_drill - - kill_emacs -} || cat robot/failure.txt diff --git a/robot/robot.sh b/robot/robot.sh new file mode 100644 index 0000000..e013308 --- /dev/null +++ b/robot/robot.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +## call find_bot to init this +window_id= + +## This is the small sleep between key presses. Change for debugging +## when you are not sure what is happening +small_sleep=0.25 +big_sleep=1 + +function sleep_small { + sleep $small_sleep +} + +function sleep_big { + sleep $big_sleep +} + +function send_answer { + retn + sleep_small + key 5 + sleep_small +} + +function launch_emacs { + echo Launching $EMACS -Q -l $1 & + $EMACS -Q -l $1 & +} + +function kill_emacs { + key alt+x + command kill-emacs + retn +} + +function key { + xdotool key --window $window_id $1 +} + +function command { + xdotool type --window $window_id $1 +} + +function retn { + xdotool key --window $window_id Return +} + +function find_bot { + window_id=`xdotool search --name "emacs-bot"` + if [ -z "$window_id" ] + then + echo "Could not find window ID for Emacs-bot" + exit 1 + fi +} -- cgit v1.2.3