|
38 | 38 | (defun crate-file (file-name)
|
39 | 39 | (expand-file-name file-name "tests/test-crate"))
|
40 | 40 |
|
| 41 | +(defun crate-with-features-file (file-name) |
| 42 | + (expand-file-name file-name "tests/crate-with-features")) |
| 43 | + |
41 | 44 | (defun lib-crate-file (file-name)
|
42 | 45 | (expand-file-name file-name "tests/custom-lib-target"))
|
43 | 46 |
|
44 | 47 | (defun build-script-crate-file (file-name)
|
45 | 48 | (expand-file-name file-name "tests/build-script-test"))
|
46 | 49 |
|
| 50 | +(defun cdrassoc (sym alist) (cdr (assoc sym alist))) |
| 51 | + |
| 52 | +(defun get-cargo-version () |
| 53 | + (let ((cargo (funcall flycheck-executable-find "cargo"))) |
| 54 | + (with-output-to-string |
| 55 | + (call-process cargo nil standard-output nil "--version")))) |
| 56 | + |
| 57 | +(defun cargo-version () |
| 58 | + (pcase-let |
| 59 | + ((`(,ignored1 ,version ,ignored2) (split-string (get-cargo-version)))) |
| 60 | + (split-string version "-"))) |
| 61 | + |
| 62 | +(defun cargo-older-than-1.29-nightly () |
| 63 | + (pcase-let ((`(,version ,channel) (cargo-version))) |
| 64 | + (or (version< version "1.29") |
| 65 | + (and (version= version "1.29") (string= channel "beta"))))) |
| 66 | + |
47 | 67 | (describe
|
48 | 68 | "`flycheck-rust-find-cargo-target' associates"
|
49 | 69 |
|
50 | 70 | (it "'src/lib.rs' to the library target"
|
51 | 71 | (expect
|
52 |
| - (car (flycheck-rust-find-cargo-target (crate-file "src/lib.rs"))) |
| 72 | + (cdrassoc 'kind (flycheck-rust-find-cargo-target (crate-file "src/lib.rs"))) |
53 | 73 | :to-equal "lib"))
|
54 | 74 |
|
55 | 75 | (it "'src/a.rs' to the library target"
|
56 | 76 | (expect
|
57 |
| - (car (flycheck-rust-find-cargo-target (crate-file "src/a.rs"))) |
| 77 | + (cdrassoc 'kind (flycheck-rust-find-cargo-target (crate-file "src/a.rs"))) |
58 | 78 | :to-equal "lib"))
|
59 | 79 |
|
60 | 80 | (it "'src/main.rs' to the main binary target"
|
61 | 81 | (expect
|
62 | 82 | (flycheck-rust-find-cargo-target (crate-file "src/main.rs"))
|
63 |
| - :to-equal '("bin" . "test-crate"))) |
| 83 | + :to-equal '((kind . "bin") (name . "test-crate")))) |
64 | 84 |
|
65 | 85 | (it "'src/bin/a.rs' to the 'a' binary target"
|
66 | 86 | (expect
|
67 | 87 | (flycheck-rust-find-cargo-target (crate-file "src/bin/a.rs"))
|
68 |
| - :to-equal '("bin" . "a"))) |
| 88 | + :to-equal '((kind . "bin") (name . "a")))) |
69 | 89 |
|
70 | 90 | (it "'src/bin/b.rs' to the 'b' binary target"
|
71 | 91 | (expect
|
72 | 92 | (flycheck-rust-find-cargo-target (crate-file "src/bin/b.rs"))
|
73 |
| - :to-equal '("bin" . "b"))) |
| 93 | + :to-equal '((kind . "bin") (name . "b")))) |
74 | 94 |
|
75 | 95 | (it "'src/bin/support/mod.rs' to any binary target"
|
76 | 96 | (expect
|
77 | 97 | (flycheck-rust-find-cargo-target (crate-file "src/bin/support/mod.rs"))
|
78 |
| - :to-equal-one-of '("bin". "a") '("bin". "b"))) |
| 98 | + :to-equal-one-of |
| 99 | + '((kind . "bin") (name . "a")) |
| 100 | + '((kind . "bin") (name . "b")))) |
79 | 101 |
|
80 | 102 | (it "'tests/a.rs' to the 'a' test target"
|
81 | 103 | (expect
|
82 | 104 | (flycheck-rust-find-cargo-target (crate-file "tests/a.rs"))
|
83 |
| - :to-equal '("test" . "a"))) |
| 105 | + :to-equal '((kind . "test") (name . "a")))) |
84 | 106 |
|
85 | 107 | (it "'tests/support/mod.rs' to any test target"
|
86 | 108 | (expect
|
87 | 109 | (flycheck-rust-find-cargo-target (crate-file "tests/support/mod.rs"))
|
88 |
| - :to-equal-one-of '("test". "a") '("test". "b"))) |
| 110 | + :to-equal-one-of |
| 111 | + '((kind . "test") (name . "a")) |
| 112 | + '((kind . "test") (name . "b")))) |
89 | 113 |
|
90 | 114 | (it "'examples/a.rs' to the 'a' example target"
|
91 | 115 | (expect
|
92 | 116 | (flycheck-rust-find-cargo-target (crate-file "examples/a.rs"))
|
93 |
| - :to-equal '("example" . "a"))) |
| 117 | + :to-equal '((kind . "example") (name . "a")))) |
94 | 118 |
|
95 | 119 | (it "'examples/b.rs' to the 'b' example target"
|
96 | 120 | (expect
|
97 | 121 | (flycheck-rust-find-cargo-target (crate-file "examples/b.rs"))
|
98 |
| - :to-equal '("example" . "b"))) |
| 122 | + :to-equal '((kind . "example") (name . "b")))) |
99 | 123 |
|
100 | 124 | (it "'examples/support/mod.rs' to any example target"
|
101 | 125 | (expect
|
102 | 126 | (flycheck-rust-find-cargo-target (crate-file "examples/support/mod.rs"))
|
103 |
| - :to-equal-one-of '("example" . "a") '("example" . "b"))) |
| 127 | + :to-equal-one-of |
| 128 | + '((kind . "example") (name . "a")) |
| 129 | + '((kind . "example") (name . "b")))) |
104 | 130 |
|
105 | 131 | (it "'benches/a.rs' to the 'a' bench target"
|
106 | 132 | (expect
|
107 | 133 | (flycheck-rust-find-cargo-target (crate-file "benches/a.rs"))
|
108 |
| - :to-equal '("bench" . "a"))) |
| 134 | + :to-equal '((kind . "bench") (name . "a")))) |
109 | 135 |
|
110 | 136 | (it "'benches/b.rs' to the 'b' bench target"
|
111 | 137 | (expect
|
112 | 138 | (flycheck-rust-find-cargo-target (crate-file "benches/b.rs"))
|
113 |
| - :to-equal '("bench" . "b"))) |
| 139 | + :to-equal '((kind . "bench") (name . "b")))) |
114 | 140 |
|
115 | 141 | (it "'benches/support/mod.rs' to any bench target"
|
116 | 142 | (expect
|
117 | 143 | (flycheck-rust-find-cargo-target (crate-file "benches/support/mod.rs"))
|
118 |
| - :to-equal-one-of '("bench" . "a") '("bench" . "b"))) |
| 144 | + :to-equal-one-of |
| 145 | + '((kind . "bench") (name . "a")) |
| 146 | + '((kind . "bench") (name . "b")))) |
119 | 147 |
|
120 | 148 | (it "'src/lib.rs' to the library target (custom-lib-target)"
|
121 | 149 | (expect
|
122 | 150 | (car (flycheck-rust-find-cargo-target (lib-crate-file "src/lib.rs")))
|
123 |
| - :to-equal "lib")) |
| 151 | + :to-equal '(kind . "lib"))) |
124 | 152 |
|
125 | 153 | (it "'build.rs' to any target in the same workspace member (parent)"
|
126 | 154 | (expect
|
127 | 155 | (flycheck-rust-find-cargo-target (build-script-crate-file "build.rs"))
|
128 |
| - :to-equal (cons "bin" "build-script-test"))) |
| 156 | + :to-equal '((kind . "bin") (name . "build-script-test")))) |
129 | 157 |
|
130 | 158 | (it "'build.rs' to any target in the same workspace member (child)"
|
131 | 159 | (expect
|
132 | 160 | (flycheck-rust-find-cargo-target (build-script-crate-file "lib-test/build.rs"))
|
133 |
| - :to-equal (cons "lib" "lib-test"))) |
| 161 | + :to-equal '((kind . "lib") (name . "lib-test")))) |
| 162 | + |
| 163 | + (it "'src/main.rs' to the bin target with required-features (fea1)" |
| 164 | + (when (cargo-older-than-1.29-nightly) |
| 165 | + (signal 'buttercup-pending "requires cargo 1.29")) |
| 166 | + (expect |
| 167 | + (flycheck-rust-find-cargo-target (crate-with-features-file "src/main.rs")) |
| 168 | + :to-equal '((kind . "bin") (name . "main") (required-features . ("fea1"))))) |
| 169 | + |
| 170 | + (it "'example/example.rs' to the example target with required-features (fea1 fea2)" |
| 171 | + (when (cargo-older-than-1.29-nightly) |
| 172 | + (signal 'buttercup-pending "requires cargo 1.29")) |
| 173 | + (expect |
| 174 | + (flycheck-rust-find-cargo-target (crate-with-features-file "example/example.rs")) |
| 175 | + :to-equal '((kind . "example") |
| 176 | + (name . "example") |
| 177 | + (required-features . ("fea1" "fea2"))))) |
134 | 178 | )
|
0 commit comments