3f299cc560
There were three related problems: 1) The first argument was always parsed with read-string, even when defaulting to the :main namespace. This caused non-numeric first arguments to throw: Exception in thread "main" java.lang.Exception: Unable to resolve symbol: foo in this context Avoid read-string entirely and update the unit tests to use an unreadable string instead of a number to make the problem obvious. This problem was reported by Marek Kubica on the Clojure mailing list. 2) When using an alias the alias keyword was passed to -main as the first argument. This is inconsistent with how the -m and :main simply pass the program arguments, not the namespace or -m flag. 3) There was no way to pass "-m" or a string beginning with ":" as a first argument to the run program. Added "--" as an option to escape these.
36 lines
1.2 KiB
Clojure
36 lines
1.2 KiB
Clojure
(ns test-run
|
|
(:use [clojure.test]
|
|
[clojure.java.io :only [delete-file]]
|
|
[leiningen.core :only [read-project]]
|
|
[leiningen.run]
|
|
[leiningen.util.file :only [tmp-dir]]))
|
|
|
|
(def out-file (format "%s/lein-test" tmp-dir))
|
|
|
|
(def project (binding [*ns* (find-ns 'leiningen.core)]
|
|
(read-project "test_projects/tricky-name/project.clj")))
|
|
|
|
(use-fixtures :each (fn [f]
|
|
(f)
|
|
(delete-file out-file :silently)))
|
|
|
|
(deftest test-basic
|
|
(is (zero? (run project "/unreadable")))
|
|
(is (= "nom:/unreadable" (slurp out-file))))
|
|
|
|
(deftest test-alt-main
|
|
(is (zero? (run project "-m" "org.domain.tricky-name.munch" "/unreadable")))
|
|
(is (= ":munched (\"/unreadable\")" (slurp out-file))))
|
|
|
|
(deftest test-aliases
|
|
(is (zero? (run project ":bbb" "/unreadable")))
|
|
(is (= "BRUNCH" (slurp out-file)))
|
|
(delete-file out-file :silently)
|
|
(is (zero? (run project ":mmm" "/unreadable")))
|
|
(is (= ":munched (\"/unreadable\")" (slurp out-file))))
|
|
|
|
(deftest test-escape-args
|
|
(is (zero? (run project "--" ":bbb")))
|
|
(is (= "nom::bbb" (slurp out-file)))
|
|
(is (zero? (run project "--" "-m")))
|
|
(is (= "nom:-m" (slurp out-file))))
|