Skip to content

Instantly share code, notes, and snippets.

@Kungi
Created September 8, 2014 12:25
Show Gist options
  • Save Kungi/c2c38c754f31ab599a11 to your computer and use it in GitHub Desktop.
Save Kungi/c2c38c754f31ab599a11 to your computer and use it in GitHub Desktop.
(ns clj-demgen.plugin-test
(:require [clj-demgen.plugin :refer :all]
[clojure.test :refer :all]
[immutant.dev]))
(defn can-resolve? [symbol]
(not (nil? (resolve symbol))))
(defn can-not-resolve? [symbol]
(not (can-resolve? symbol)))
(deftest initially-cannot-resolve-plugin-ns []
(is (can-not-resolve? 'demgen-plugin.test-plugin.core/main)
"Plugin main namespace cannot be resolved without loading the plugin first."))
(deftest plugin-cannot-be-loaded-without-load-plugin []
(require 'demgen-plugin.test-plugin.core)
(is (can-not-resolve? 'demgen-plugin.test-plugin.core/main)
"When plugin is not loaded require does not make the main namespace availible."))
(deftest load-plugin-test []
(load-plugin '[demgen-plugin/test-plugin "0.1.0-SNAPSHOT"]
'demgen-plugin.test-plugin.core)
(is (can-resolve? 'demgen-plugin.test-plugin.core/main)
"After loading the plugin the main namespace can be resolved.")
(unload-plugin '[demgen-plugin/test-plugin "0.1.0-SNAPSHOT"]
'demgen-plugin.test-plugin.core)
(is (can-not-resolve? 'demgen-plugin.test-plugin.core/main)
"After unloading the plugin the main namespace cannot be resolved."))
(ns clj-demgen.plugin
(:require [immutant.dev]
[clojure.set :as set]))
(defn remove-dependencies!
[& deps]
(immutant.dev/reload-project!
(-> (immutant.dev/current-project)
(update-in [:dependencies] #(vec (set/difference (set %) (set deps)))))))
(defn load-plugin [coordinate main-ns]
(immutant.dev/add-dependencies! coordinate)
(require main-ns :reload))
(defn unload-plugin [coordinate main-ns]
(remove-ns main-ns)
(remove-dependencies! coordinate))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment