Skip to content

Instantly share code, notes, and snippets.

@coreagile
Last active August 29, 2015 14:08
Show Gist options
  • Save coreagile/340d49e77a82c77afadb to your computer and use it in GitHub Desktop.
Save coreagile/340d49e77a82c77afadb to your computer and use it in GitHub Desktop.
Trouble with introducing core.typed using TDD
# Introducing core.typed in this patch:
# https://github.com/courage-labs/freefrog/commit/cf81d1435d364e5da6be3d11714c79de14f6ef57
# Causes this unexpected result (I was hoping it would tell me that this namespace wasn't annotated
# how do I do that?):
Stephen-Starkeys-MacBook-Air-11:freefrog scstarkey$ lein spec spec/freefrog/governance_spec.clj
Initializing core.typed ...
Building core.typed base environments ...
Finished building base environments
"Elapsed time: 12446.426555 msecs"
core.typed initialized.
Start collecting freefrog.governance
Finished collecting freefrog.governance
Collected 1 namespaces in 1550.305381 msecs
Not checking freefrog.governance (tagged :collect-only in ns metadata)
Checked 1 namespaces in 1558.975731 msecs
.
Finished in 14.04928 seconds
1 examples, 0 failures
# note: adding a require for [clojure.core.typed :as t] in the src/freefrog/governance.clj
# namespace declaration causes everything to work as expected (as in: the spec fails and I get
# tons of hints about what to do to fix everything).
diff --git a/project.clj b/project.clj
index 1761e60..105dea4 100644
--- a/project.clj
+++ b/project.clj
@@ -10,6 +10,7 @@
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/core.typed "0.2.72"]
+ [org.clojure/tools.namespace "0.2.7"]
[com.velisco/tagged "0.3.4"]
[clj-jgit "0.8.0"]
[speclj "3.1.0"]]
diff --git a/spec/freefrog/governance_spec.clj b/spec/freefrog/governance_spec.clj
index 01febf6..4335d3f 100644
--- a/spec/freefrog/governance_spec.clj
+++ b/spec/freefrog/governance_spec.clj
@@ -1,7 +1,27 @@
(ns freefrog.governance-spec
(:require [clojure.core.typed :as t]
+ [clojure.java.io :as io]
+ [clojure.tools.namespace.file :as ns-file]
+ [clojure.tools.namespace.track :as ns-track]
+ [clojure.tools.namespace.find :as ns-find]
+ [clojure.tools.namespace.dependency :as ns-dep]
[speclj.core :refer :all]))
+(def dep-graph
+ (let [src-files (ns-find/find-clojure-sources-in-dir (io/file "src"))
+ tracker (ns-file/add-files {} src-files)]
+ (tracker ::ns-track/deps)))
+
+(defmacro should-depend
+ "Asserts ns1 depends on ns2"
+ [ns1 ns2]
+ `(let [ns1# ~ns1
+ ns2# ~ns2]
+ (if-not (ns-dep/depends? dep-graph ns1# ns2#)
+ (-fail (format "Expected %s to depend on %s but it did not"
+ ns1# ns2#)))))
+
(describe "governance namespace"
(it "should be fully type-safe"
+ (should-depend 'freefrog.governance 'clojure.core.typed)
(should (t/check-ns 'freefrog.governance))))
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment