Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59884d2

Browse files
xiongtxbbatsov
authored andcommittedJan 3, 2018
[Fix #466] Use dedicated file / function for debugging test (#467)
1 parent b1469f1 commit 59884d2

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed
 

‎project.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@
6868
:master {:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]
6969
:dependencies [[org.clojure/clojure "1.10.0-master-SNAPSHOT"]]}
7070

71-
:test-clj {:test-paths ["test/clj"]
71+
:test-clj {:source-paths ["test/src"]
7272
:java-source-paths ["test/java"]
73-
:resource-paths ["test/resources"]}
73+
:resource-paths ["test/resources"]
74+
:test-paths ["test/clj"]}
7475
:test-cljs {:test-paths ["test/cljs"]
7576
:dependencies [[com.cemerick/piggieback "0.2.2"]
7677
[org.clojure/clojurescript "1.7.189"]]}

‎test/clj/cider/nrepl/middleware/debug_integration_test.clj

+19-20
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,18 @@
470470
(<-- {:status ["done"]}))
471471

472472
(deftest step-in-to-function-in-current-project-test
473-
;; We use misc/as-sym just because it's a simple function that's part of the
474-
;; current project, and we want to ensure that the debugger can find and
475-
;; instrument the code of a function that lives in a regular file on the
476-
;; classpath (as opposed to, for example, in a jar, which is tested later).
473+
;; We want to ensure that the debugger can find and instrument the code of a
474+
;; function that lives in a regular file on the classpath (as opposed to,
475+
;; for example, in a jar, which is tested later).
477476
(--> :eval "(ns user.test.step-in
478-
(:require [cider.nrepl.middleware.util.misc :as misc]))")
477+
(:require [cider.nrepl.middleware.debug-integration-test.fn :as test-fn]))")
479478
(<-- {:ns "user.test.step-in"})
480479
(<-- {:status ["done"]})
481480

482481
(--> :eval
483482
"#dbg
484483
(defn foo [s]
485-
(misc/as-sym s))")
484+
(test-fn/as-sym s))")
486485
(<-- {:value "#'user.test.step-in/foo"})
487486
(<-- {:status ["done"]})
488487

@@ -491,21 +490,21 @@
491490
(<-- {:debug-value "\"bar\""})
492491
(--> :in)
493492

494-
;; Note - if anyone changes misc.clj, this could fail:
495-
(let [msg (<-- {:line 32
493+
;; Note - if changing test/src/cider/nrepl/middleware/debug_integration_test/fn.clj, also change this:
494+
(let [msg (<-- {:line 7
496495
:column 0
497496
:debug-value "\"bar\""
498497
:coor [3 1 1]
499498
:locals [["x" "\"bar\""]]})
500-
misc-file (:file msg)]
501-
(is (.endsWith misc-file "/cider/nrepl/middleware/util/misc.clj"))
502-
(is (.startsWith misc-file "file:/"))
499+
file (:file msg)]
500+
(is (.endsWith file "/cider/nrepl/middleware/debug_integration_test/fn.clj"))
501+
(is (.startsWith file "file:/"))
503502

504-
;; Step out a couple of times, taking us out of misc/as-sym
503+
;; Step out a couple of times, taking us out of test-fn/as-sym
505504
(--> :out)
506-
(<-- {:debug-value "false" :file misc-file})
505+
(<-- {:debug-value "false" :file file})
507506
(--> :out)
508-
(<-- {:debug-value "bar" :file misc-file})
507+
(<-- {:debug-value "bar" :file file})
509508

510509
;; Next step should take us back into foo
511510
(--> :next)
@@ -518,23 +517,23 @@
518517
(--> :eval "(foo \"bar\")")
519518
(<-- {:debug-value "\"bar\""})
520519
(--> :next)
521-
(<-- {:debug-value "bar" :coor [3]}) ; return value of (misc/as-sym ...)
520+
(<-- {:debug-value "bar" :coor [3]}) ; return value of (test-fn/as-sym ...)
522521
(--> :continue)
523522
(<-- {:value "bar"})
524523
(<-- {:status ["done"]}))
525524

526525
(testing "stepped-in-to functions are not instrumented"
527-
;; Test that stepped-in-to functions are not instrumented - that is, calling
528-
;; misc/as-sym directly now should not invoke the debugger, even though we
529-
;; were stepping through its code in the test above.
530-
(--> :eval "(misc/as-sym \"bar\")")
526+
;; Test that stepped-in-to functions are not instrumented - that is,
527+
;; calling test-fn/as-sym directly now should not invoke the debugger,
528+
;; even though we were stepping through its code in the test above.
529+
(--> :eval "(test-fn/as-sym \"bar\")")
531530
(<-- {:value "bar"})
532531
(<-- {:status ["done"]}))
533532

534533
(testing ":in command acts as :next on non-function"
535534
(--> :eval "#dbg (let [s \"blah\"]
536535
s
537-
(misc/as-sym s))")
536+
(test-fn/as-sym s))")
538537
(<-- {:debug-value "\"blah\"" :coor [2]})
539538
;; try to step in to `s`, make sure nothing blows up
540539
(--> :in)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns cider.nrepl.middleware.debug-integration-test.fn
2+
"Function for debug integration test.
3+
4+
NOTE: if modifying this file, modify corresponding tests in
5+
debug_integration_test.clj.")
6+
7+
(defn as-sym
8+
[x]
9+
(cond
10+
(symbol? x) x
11+
(string? x) (if-let [[_ ns sym] (re-matches #"(.+)/(.+)" x)]
12+
(symbol ns sym)
13+
(symbol x))))

0 commit comments

Comments
 (0)
Please sign in to comment.