|
7 | 7 | (:import [java.io StringWriter]))
|
8 | 8 |
|
9 | 9 | (defn- const-opts
|
10 |
| - [v] |
| 10 | + [v & [extra-opts]] |
11 | 11 | (o/options
|
12 |
| - {:plugins? true |
13 |
| - :repositories |
14 |
| - {"const" (constantly [v])}})) |
| 12 | + (merge |
| 13 | + extra-opts |
| 14 | + {:plugins? true |
| 15 | + :repositories |
| 16 | + {"const" (constantly [v])}}))) |
| 17 | + |
| 18 | +(defn- test-upgrade! |
| 19 | + [?file opts contents expected outdated-count] |
| 20 | + (with-temp-file [tmp contents] |
| 21 | + (let [f (?file tmp) |
| 22 | + r (read! f)] |
| 23 | + (is (satisfies? Dependencies f)) |
| 24 | + (is (satisfies? Dependencies r)) |
| 25 | + (let [outdated (check! r opts)] |
| 26 | + (is (= outdated-count (count outdated))) |
| 27 | + (is (every? :latest outdated)) |
| 28 | + (is (every? #{"0.1.1"} (map (comp :version-string :latest) outdated))) |
| 29 | + (let [u (upgrade! r outdated)] |
| 30 | + (is (satisfies? Dependencies u)) |
| 31 | + (is (= expected (write-string! u))) |
| 32 | + (write-out! u) |
| 33 | + (is (= expected (slurp tmp)))))))) |
15 | 34 |
|
16 | 35 | (deftest t-project-file-upgrading
|
17 | 36 | (are [?fmt ?file]
|
|
21 | 40 | opts (const-opts "0.1.1")
|
22 | 41 | contents (format ?fmt (pr-str ?artifact))
|
23 | 42 | expected (format ?fmt (pr-str upgraded))]
|
24 |
| - (with-temp-file [tmp contents] |
25 |
| - (let [f (?file tmp) |
26 |
| - r (read! f)] |
27 |
| - (is (satisfies? Dependencies f)) |
28 |
| - (is (satisfies? Dependencies r)) |
29 |
| - (let [outdated (check! r opts)] |
30 |
| - (is (= 1 (count outdated))) |
31 |
| - (is (every? :latest outdated)) |
32 |
| - (is (every? #{"0.1.1"} (map (comp :version-string :latest) outdated))) |
33 |
| - (let [u (upgrade! r outdated)] |
34 |
| - (is (satisfies? Dependencies u)) |
35 |
| - (is (= expected (write-string! u))) |
36 |
| - (write-out! u) |
37 |
| - (is (= expected (slurp tmp)))))))) |
| 43 | + (test-upgrade! ?file opts contents expected 1)) |
38 | 44 | '[artifact]
|
39 | 45 | '[artifact "0.1.0"]
|
40 | 46 | '[artifact "0.1.0" :exclusions [other]])
|
41 | 47 | (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
|
42 | 48 | " :dependencies [%s])")
|
43 | 49 | project-file
|
44 | 50 |
|
45 |
| - (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n" |
46 |
| - " :managed-dependencies [%s])") |
47 |
| - project-file |
48 |
| - |
49 |
| - (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n" |
50 |
| - " :dependencies [[artifact]]" |
51 |
| - " :managed-dependencies [%s])") |
52 |
| - project-file |
53 |
| - |
54 | 51 | (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
|
55 | 52 | " :dependencies [#_[ignore] %s])")
|
56 | 53 | project-file
|
|
63 | 60 | " %s]}")
|
64 | 61 | #(profiles-file % [:profiles :prof])))
|
65 | 62 |
|
| 63 | +(deftest t-project-file-upgrading-with-managed-dependencies |
| 64 | + (are [?fmt ?outdated-count] |
| 65 | + (are [?artifact] |
| 66 | + (let [[a _ & rst] ?artifact |
| 67 | + upgraded (reduce conj [a "0.1.1"] rst) |
| 68 | + opts (const-opts |
| 69 | + "0.1.1" |
| 70 | + {:managed-dependencies '[[artifact "0.2.0"]]}) |
| 71 | + contents (format ?fmt (pr-str ?artifact)) |
| 72 | + expected (format ?fmt (pr-str upgraded))] |
| 73 | + (test-upgrade! project-file opts contents expected ?outdated-count)) |
| 74 | + '[artifact "0.1.0"] |
| 75 | + '[artifact "0.1.0" :exclusions [other]]) |
| 76 | + (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n" |
| 77 | + " :managed-dependencies [%s])") |
| 78 | + 1 |
| 79 | + |
| 80 | + (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n" |
| 81 | + " :dependencies [[artifact]]" |
| 82 | + " :parent-project {:path \"parent.clj\"" |
| 83 | + " :inherit [:managed-dependencies]})") |
| 84 | + 0 |
| 85 | + |
| 86 | + (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n" |
| 87 | + " :dependencies [[artifact]]" |
| 88 | + " :managed-dependencies [%s])") |
| 89 | + 1)) |
| 90 | + |
66 | 91 | (deftest t-project-file-upgrading-failure-because-of-modifications
|
67 | 92 | (let [opts (const-opts "0.1.1")
|
68 | 93 | contents (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
|
|
0 commit comments