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