Skip to content

Commit 4036705

Browse files
xiongtxbbatsov
authored andcommitted
Dynamically build structs in nrepl-bencode-tests
Fixes #2133 In Emacs 26, the print representations of structs changed from `[cl-struct ...]` to `#s(...)`. This broke tests that compare structs against print representations. Building structs dynamically resolves this.
1 parent 95c7e6b commit 4036705

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

test/nrepl-bencode-tests.el

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
;;; Code:
2929

3030
(require 'buttercup)
31+
(require 'cl-lib)
3132
(require 'nrepl-client)
3233

3334
(defun nrepl-bdecode-string (string)
@@ -74,8 +75,10 @@ If object is incomplete, return a decoded path."
7475
(it "decodes queues"
7576
(expect (nrepl-bdecode "lli1ei2ei3eeli5ei6eee")
7677
:to-equal (cons
77-
[cl-struct-queue nil nil]
78-
[cl-struct-nrepl-response-queue (((1 2 3) (5 6))) (((1 2 3) (5 6))) nil])))
78+
(make-queue)
79+
(let ((q (nrepl-response-queue)))
80+
(queue-enqueue q '((1 2 3) (5 6)))
81+
q))))
7982

8083
(it "decodes list of ints"
8184
(expect (nrepl-bdecode-string "li1ei2ei3ei4ei5ei6ei7ei8ee")
@@ -164,28 +167,25 @@ If object is incomplete, return a decoded path."
164167
items, returns val and f is not called.
165168
7:session36:6fc999d0-3795-4d51-85fc-ccca7537ee57ed2:id2:182:ns4:user7:session36:6fc999d0-3795-4d51-85fc-ccca7537ee575:value3:niled2:id2:187:session36:6fc999d0-3795-4d51-85fc-ccca7537ee576:statusl4:doneee")
166169
:to-equal (cons
167-
[cl-struct-queue nil nil]
168-
[cl-struct-nrepl-response-queue
169-
((dict "id" "18"
170-
"out" "clojure.core/reduce\n"
171-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
172-
(dict "id" "18"
173-
"out" "([f coll] [f val coll])\n"
174-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
175-
(dict "id" "18"
176-
"out" " f should be a function of 2 arguments. If val is not supplied,\n returns the result of applying f to the first 2 items in coll, then\n applying f to that result and the 3rd item, etc. If coll contains no\n items, f must accept no arguments as well, and reduce returns the\n result of calling f with no arguments. If coll has only 1 item, it\n is returned and f is not called. If val is supplied, returns the\n result of applying f to val and the first item in coll, then\n applying f to that result and the 2nd item, etc. If coll contains no\n items, returns val and f is not called.\n"
177-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
178-
(dict "id" "18"
179-
"ns" "user"
180-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57"
181-
"value" "nil")
182-
(dict "id" "18"
183-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57"
184-
"status" ("done")))
185-
((dict "id" "18"
186-
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57"
187-
"status" ("done")))
188-
nil])))
170+
(make-queue)
171+
(cl-reduce (lambda (q dict) (queue-enqueue q dict) q)
172+
'((dict "id" "18"
173+
"out" "clojure.core/reduce\n"
174+
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
175+
(dict "id" "18"
176+
"out" "([f coll] [f val coll])\n"
177+
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
178+
(dict "id" "18"
179+
"out" " f should be a function of 2 arguments. If val is not supplied,\n returns the result of applying f to the first 2 items in coll, then\n applying f to that result and the 3rd item, etc. If coll contains no\n items, f must accept no arguments as well, and reduce returns the\n result of calling f with no arguments. If coll has only 1 item, it\n is returned and f is not called. If val is supplied, returns the\n result of applying f to val and the first item in coll, then\n applying f to that result and the 2nd item, etc. If coll contains no\n items, returns val and f is not called.\n"
180+
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57")
181+
(dict "id" "18"
182+
"ns" "user"
183+
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57"
184+
"value" "nil")
185+
(dict "id" "18"
186+
"session" "6fc999d0-3795-4d51-85fc-ccca7537ee57"
187+
"status" ("done")))
188+
:initial-value (nrepl-response-queue)))))
189189

190190
(it "decodes nrepl responses with multibyte chars"
191191
(expect (nrepl-bdecode-string
@@ -214,9 +214,12 @@ If object is incomplete, return a decoded path."
214214
(it "decodes queues"
215215
(expect (nrepl-bdecode "lli1ei2ei3eeli5ei6eeelli1ei2ei3eeli5ei6")
216216
:to-equal (cons
217-
[cl-struct-queue ("i6") ("i6")]
218-
[cl-struct-nrepl-response-queue (((1 2 3) (5 6))) (((1 2 3) (5 6)))
219-
((5) ((1 2 3)))]))))
217+
(let ((q (make-queue)))
218+
(queue-enqueue q "i6")
219+
q)
220+
(let ((q (nrepl-response-queue '((5) ((1 2 3))))))
221+
(queue-enqueue q '((1 2 3) (5 6)))
222+
q)))))
220223

221224
(describe "when bencode strings are split into parts"
222225
(it "decodes dict"

0 commit comments

Comments
 (0)