diff options
Diffstat (limited to 'features')
| -rw-r--r-- | features/highlight.feature | 67 | ||||
| -rw-r--r-- | features/ics.feature | 12 | ||||
| -rw-r--r-- | features/premove.feature | 34 | ||||
| -rw-r--r-- | features/step-definitions/emacs-chess-steps.el | 146 | ||||
| -rw-r--r-- | features/support/env.el | 33 |
5 files changed, 283 insertions, 9 deletions
diff --git a/features/highlight.feature b/features/highlight.feature new file mode 100644 index 0000000..fd72ea9 --- /dev/null +++ b/features/highlight.feature @@ -0,0 +1,67 @@ +Scenario: legal highlights should not persist across piece selection + Given I start server and client + Then I am ready to play + When white selects "d2" + And white selects "d2" + And white selects "e2" + Given I switch to buffer "*Chessboard*" + Then the square at "d3" is unhighlighted + +Scenario: preserve last-move highlight after changing my mind + Given I start server and client + Then I am ready to play + When white moves "d4" + And black moves "e5" + And white selects "d4" + And white selects "d4" + Then the square at "e5" is highlighted last-move + When black selects "e5" + And black selects "e5" + Then the square at "e5" is highlighted last-move + +Scenario: preserve last-move highlight after pre-move invalidated + Given I start server and client + Then I am ready to play + When white moves "d4" + And black moves "e5" + And white moves "e4" + And white moves "d5" + Then the square at "d5" is highlighted pre-move + When black moves "ex" + Given I switch to buffer "*Chessboard*" + Then the square at "d4" is highlighted last-move + +Scenario: Legal highlight locus must needs reduce after opponent moves + Given I start server and client + Then I am ready to play + When white moves "d4" + And black moves "d5" + And black selects "e7" + Then the square at "e5" is highlighted legal + Then the square at "f6" is highlighted legal + And white moves "e4" + Given I switch to buffer "*Chessboard*<2>" + Then the square at "e5" is highlighted legal + Then the square at "f6" is unhighlighted + +Scenario: My opponent invalidates my pre-move. I should not need to click twice for next selection. + Given I start server and client + Then I am ready to play + And white moves "d4" + And black moves "e5" + When black selects "e5" + Then the square at "e5" is highlighted selected + Then the square at "e4" is highlighted legal + And white moves "dx" + Given I switch to buffer "*Chessboard*<2>" + Then the square at "e5" is highlighted last-move + Then the square at "e4" is unhighlighted + When black selects "c7" + Then the square at "c7" is highlighted selected + +Scenario: paint-move had contained a redraw that was 2000 microseconds (still 1/200 of blink of an eye) + Given I start server and client + Then I am ready to play + When white moves "d4" + And black moves "c5" + And paint-move last 2 plies less than 300 microseconds (individually) diff --git a/features/ics.feature b/features/ics.feature index 5a49dfe..fcb7706 100644 --- a/features/ics.feature +++ b/features/ics.feature @@ -3,3 +3,15 @@ Scenario: Echo area should indicate opponent ran out of time. When new game And opponent forfeits on time Then I should see message "Your opponent has forfeited the game on time" + +Scenario: Let me know when opponent aborts + Given ics session + When new game + And opponent aborts + Then I should see message "Your offer to abort was accepted" + +Scenario: Let me know when opponent forfeits by disconnection + Given ics session + When new game + And opponent forfeits by disconnection + Then I should see message "Your opponent has resigned" diff --git a/features/premove.feature b/features/premove.feature new file mode 100644 index 0000000..47cf85f --- /dev/null +++ b/features/premove.feature @@ -0,0 +1,34 @@ +Scenario: en-passant logic assumed no pre-moves (white) + Given I start server and client + Then I am ready to play + When white moves "d4" + And white selects "d4" + Then the square at "d3" is unhighlighted + +Scenario: en-passant logic assumed no pre-moves (black) + Given I start server and client + Then I am ready to play + When white moves "d4" + And black moves "e5" + And black selects "e5" + Then the square at "e6" is unhighlighted + +Scenario: pre-move can leave king in check, assuming checking piece is captured + Given I start server and client + Then I am ready to play + And I set position of "*chess-network*<1>" to fen "3rk3/8/8/3R4/8/8/PPPPPPPP/1NBQKBNR w - -" + And I send position from "*chess-network*<1>" + When black selects "e8" + And black selects "d8" + Then the square at "d8" is highlighted pre-move + + +Scenario: pre-move promotion should not ask yet + Given I start server and client + Then I am ready to play + And I set position of "*chess-network*<1>" to fen "rnbqkbn1/pppppppP/8/8/8/8/PPPPPPP1/RNBQKBNR w - -" + And I send position from "*chess-network*<1>" + And white moves "d4" + And white selects "h7" + And white selects "h8" + Then the square at "h8" is highlighted pre-move diff --git a/features/step-definitions/emacs-chess-steps.el b/features/step-definitions/emacs-chess-steps.el index 5e1b6cc..b0d2ae0 100644 --- a/features/step-definitions/emacs-chess-steps.el +++ b/features/step-definitions/emacs-chess-steps.el @@ -9,7 +9,7 @@ (process-send-string test-fifo "login:\n") (process-send-string test-fifo "Logging you in as \"GuestME\"\n") (process-send-string test-fifo "fics% \n") - (sleep-for 3) + (sleep-for 2) (chess-ics "nowhere.org" 5000 nil nil "sh" "-c" (format "cat %s" test-fn)) ))) @@ -20,16 +20,35 @@ (process-send-string test-fifo (format "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 23 GuestYOU GuestME -1 5 5 39 39 300 300 1 none (0:00) none 1 0 0\n")) (process-send-string test-fifo (format "<12> rnbqkbnr pppppppp -------- -------- --P----- -------- PP-PPPPP RNBQKBNR B 2 1 1 1 1 0 23 GuestYOU GuestME 1 5 5 39 39 300 300 1 P/c2-c4 (0:00) c4 1 0 0\n")) (process-send-string test-fifo (format "<12> rnbqkbnr pppp-ppp -------- ----p--- --P----- -------- PP-PPPPP RNBQKBNR W 4 1 1 1 1 0 23 GuestYOU GuestME -1 5 5 39 39 300 300 2 P/e7-e5 (0:00) e5 1 1 0\n")) - (sleep-for 3) + (sleep-for 2) ) ) (When "^opponent forfeits on time$" (lambda () (process-send-string test-fifo (format "{Game 42 (GuestYOU vs. GuestME) GuestYOU forfeits on time} 0-1\n")) - (sleep-for 3) + (sleep-for 2) )) +(When "^opponent forfeits by disconnection$" + (lambda () + (process-send-string test-fifo (format "{Game 42 (GuestYOU vs. GuestME) GuestYOU forfeits by disconnection} 1-0\n")) + (sleep-for 2) + )) + +(When "^opponent aborts$" + (lambda () + (process-send-string test-fifo (format "Your opponent has aborted the game on move one.\n")) + (sleep-for 2) + )) + +(When "^I specify a good port$" + (lambda () + (if espuds-chain-active + (progn + (setq espuds-action-chain (vconcat espuds-action-chain (string-to-vector test-port)))) + (execute-kbd-macro (string-to-vector test-port))))) + (Given "^game with fen \"\\(.+\\)\"$" (lambda (fen) (let ((game (chess-game-create (chess-fen-to-pos fen))) objects) @@ -37,6 +56,22 @@ 'chess--create-display game t t)))))) +(When "^I set position of \"\\(.+\\)\" to fen \"\\(.+\\)\"$" + (lambda (process-name fen) + (chess-with-current-buffer (process-buffer (get-process process-name)) + (chess-engine-set-position nil (chess-fen-to-pos fen))) + (sleep-for 2) +)) + + +(When "^I send position from \"\\(.+\\)\"$" + (lambda (process-name) + (chess-with-current-buffer (process-buffer (get-process process-name)) + (chess-game-run-hooks chess-module-game 'setup-pos (chess-game-pos chess-module-game))) + (sleep-for 2) +)) + + (Then "^the move \"\\([a-h][1-8]\\)-\\([a-h][1-8]\\)\" is illegal$" (lambda (source target) (let ((position (chess-display-position test-display))) @@ -44,4 +79,109 @@ (chess-coord-to-index source) (chess-coord-to-index target))))))) +(Then "^I am ready to play$" + (lambda () + (let ((ready (apply 'chess-string 'opp-ready (list user-full-name)))) + (Then "I should see message \"%s\"" ready)))) + +(When "^\\(white\\|black\\) moves \"\\(.+\\)\"$" + (lambda (color move) + (if (string= "white" color) + (Given "I switch to buffer \"*Chessboard*\"") + (Given "I switch to buffer \"*Chessboard*<2>\"")) + (When "I type \"%s\"" move) + (sleep-for 1) +)) + +(When "^\\(white\\|black\\) selects \"\\([a-h][1-8]\\)\"$" + (lambda (color source) + (if (string= "white" color) + (Given "I switch to buffer \"*Chessboard*\"") + (Given "I switch to buffer \"*Chessboard*<2>\"")) + (When "I go to point \"%s\"" (number-to-string (chess-display-index-pos nil (chess-coord-to-index source)))) + (When "I press \"RET\"") + (sleep-for 1) +)) + +(Then "^paint-move last \\([0-9]+\\) plies less than \\([0-9]+\\) microseconds" + (lambda (times micros) + (dotimes (i (string-to-number times)) + (let ((ply (chess-game-ply chess-module-game (1- (- chess-display-index i))))) + (assert (< (measure-time (chess-display-paint-move nil ply)) + (/ (string-to-number micros) 1e6))))))) + +(Given "^I start server and client$" + (lambda () + (Given "I start server") + (sleep-for 1) + (Given "I start client") + (sleep-for 1) + )) + +(Given "^I start server$" + (lambda () + (And "I start an action chain") + (And "I press \"C-u M-x\"") + (And "I type \"chess\"") + (And "I press \"RET\"") + (And "I type \"network\"") + (And "I press \"RET\"") + (And "I press \"s\"") + (And "I specify a good port") + (And "I press \"RET\"") + (And "I execute the action chain"))) + +(Given "^I start client$" + (lambda () + (And "I start an action chain") + (And "I press \"C-u M-x\"") + (And "I type \"chess\"") + (And "I press \"RET\"") + (And "I type \"network\"") + (And "I press \"RET\"") + (And "I press \"c\"") + (And "I type \"localhost\"") + (And "I press \"RET\"") + (And "I specify a good port") + (And "I press \"RET\"") + (And "I execute the action chain") +)) + +(Then "^the square at \"\\([a-h][1-8]\\)\" is highlighted \\(.+\\)$" + (lambda (source kind) + (if (display-graphic-p) + (let ((prop (copy-alist (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'display)))) + (chess-display-highlight nil + (cond ((string= kind "selected") + chess-images-highlight-color) + ((string= kind "pre-move") + chess-display-pre-move-color) + ((string= kind "last-move") + chess-display-last-move-color) + ((string= kind "legal") + chess-display-legal-move-color) + (t chess-display-last-move-color)) + (chess-coord-to-index source)) + (assert (equal prop (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'display)))) + (assert (eq (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'face) (cond ((string= kind "selected") 'chess-ics1-highlight-face) + (t 'chess-display-highlight))))))) +(Then "^the square at \"\\([a-h][1-8]\\)\" is unhighlighted$" + (lambda (source) + (if (display-graphic-p) + (let ((prop (copy-alist (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'display)))) + (chess-display-unhighlight-square nil (chess-coord-to-index source)) + (assert (equal prop (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'display)))) + (assert (not (eq (get-text-property + (chess-display-index-pos nil (chess-coord-to-index source)) + 'face) 'chess-display-highlight)))))) diff --git a/features/support/env.el b/features/support/env.el index 58ed42f..3429e34 100644 --- a/features/support/env.el +++ b/features/support/env.el @@ -9,9 +9,17 @@ (defvar emacs-chess-root-path (f-parent emacs-chess-features-path)) +;; Nikolaj Schumacher +(defmacro measure-time (&rest body) + "Measure the time it takes to evaluate BODY." + `(let ((time (current-time))) + ,@body + (float-time (time-since time)))) + (add-to-list 'load-path emacs-chess-root-path) (require 'chess-ics) +(require 'chess) (require 'espuds) (require 'ert) (require 'cl) @@ -19,6 +27,18 @@ (Setup (defvar test-display nil) (defvar test-fifo nil) + (defvar test-port nil) + (setq test-port (catch 'loop + (dolist (cand (list "5678" "5413" "5142" "5308" "5987")) + (when (= 1 (call-process "nc" nil nil nil "-z" "localhost" cand)) + (throw 'loop cand))))) + (setq noninteractive t) + (custom-set-variables '(chess-sound-moves nil) + '(chess-display-highlight-last-move t) + '(chess-display-highlight-legal t) + '(chess-display-popup nil) + '(chess-display-allow-pre-moves t) + '(chess-images-separate-frame nil)) ) (Before @@ -30,12 +50,13 @@ (when test-display (chess-module-destroy test-display) (setq test-display nil)) - (when (process-status "*chess-ics*") - (delete-process "*chess-ics*")) - (when test-fifo - (process-send-eof test-fifo) - (delete-process test-fifo) - (setq test-fifo nil)) + (dolist (p (process-list)) + (delete-process p)) + (setq test-fifo nil) + (let ((buf (get-buffer "*Chessboard*")) + (buf2 (get-buffer "*Chessboard*<2>"))) + (if buf (kill-buffer buf)) + (if buf2 (kill-buffer buf2))) ) (Teardown |
