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