Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dedicated clojure.spec/assert stacktrace handling #440

Merged
merged 2 commits into from
Oct 1, 2017

Conversation

vspinu
Copy link
Contributor

@vspinu vspinu commented Aug 26, 2017

(defn prepare-spec-data [ed pprint-fn]
(let [pp-str #(with-out-str (pprint-fn %))
problems (sort-by #(count (:path %)) (:clojure.spec.alpha/problems ed))]
;; (prn {:ed ed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some debug statements leftover here.

@expez
Copy link
Member

expez commented Aug 27, 2017

I restarted the tests because the coverage was failing, but I'm not sure how they're generally green on 1.7 where spec can't even be required.

To solve that, in a previous pr, I remember a new test-selector was added:

(deftest ^{:min-clj-version "1.9.0-alpha16"} spec-list-integration-test
  (let [filter-regex "clojure"
        filtered-spec-list (:spec-list (session/message {:op "spec-list"
                                                         :filter-regex filter-regex}))]    
    (testing "Filtered spec list retrieving nothing extra"
      (is (every? #(re-find (re-pattern (str ":?" filter-regex)) %)
                  filtered-spec-list)))
    (testing "Filtering with simple words regex"
      (is (= (count filtered-spec-list)
             (count (:spec-list (session/message {:op "spec-list"
                                                  :filter-regex (str filter-regex ".+")}))))))))

This looks like another great addition btw! 👍

@vspinu
Copy link
Contributor Author

vspinu commented Aug 27, 2017

One or two tests in a matrix usually fail for unrelated reasons. It's mostly 7th, but could be some other. I guess it's because travis chokes on resources on parallel builds or something like that. You should restart the failing test only.

, but I'm not sure how they're generally green on 1.7 where spec can't even be required.

Spec tests are not run on 1.7. Those are in dedicated "test/spec" directory which is added to tests-src in 1.9 build only. It's harder to do otherwise because one would need to require clojure.spec.alpha conditionally.

@@ -187,6 +188,37 @@
(when-let [data (ex-data e)]
(into {} (filter (comp (complement ex-data-blacklist) key) data))))


(def spec-abbrev (delay
(if (try (require 'clojure.spec.alpha) true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me you should check for the non-alpha version of the ns as well, as it's eventually going to be released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

(resolve 'clojure.spec.alpha/abbrev)
#'identity)))

(defn prepare-spec-data [ed pprint-fn]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this could use a docstring.


(defn prepare-spec-data [ed pprint-fn]
(let [pp-str #(with-out-str (pprint-fn %))
problems (sort-by #(count (:path %)) (:clojure.spec.alpha/problems ed))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried about the hardcoded alpha namespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to fix this would be to create a correct namespace in try-catch from above and create an alias there. Will think of something.

:predicate (pr-str (@spec-abbrev pred))
:reason reason ; <- always nil or string
:spec (when-not (empty? via) (pr-str (last via)))
:at (when-not (empty? path) (pr-str path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you added an extra space here.

(pp-str extras)))}
(filter clojure.core/val)
(into {})))}))

(defn analyze-cause
"Return a map describing the exception cause. If `ex-data` exists, a `:data`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess you can mention this now does some spec-related stuff as well.

@bbatsov
Copy link
Member

bbatsov commented Sep 17, 2017

Apart from my small remarks - everything looks good to me.

@bbatsov bbatsov merged commit efb1b00 into clojure-emacs:master Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants