-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As flycheck/flycheck#1206 has added support for the full conventional project layout, flycheck-rust should be able to automatically set the variables for all files in the project as well. This commit uses `cargo --read-manifest` to get a list of build targets for the project, and try to determine the correct values for the -rust-crate-type and -rust-binary-name variables. As Cargo doesn't actually read the files to determine the targets, we have no way to know if a file will be compiled, but if the project follows the conventional layout, we should get it right most of the time. If not, users can always override the variables using local variables. This commit adds test to make sure the association of files to targets works on a dummy project.
- Loading branch information
Showing
20 changed files
with
219 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2016 fmdkdd | ||
|
||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later | ||
# version. | ||
|
||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
|
||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
CASK = cask | ||
|
||
.PHONY: init | ||
init: | ||
$(CASK) install | ||
$(CASK) update | ||
|
||
.PHONY: test | ||
test: | ||
$(CASK) exec buttercup -L . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "test-crate" | ||
version = "0.1.0" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
;;; test-rust-setup.el -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2016 fmdkdd | ||
|
||
;; Author: fmdkdd | ||
|
||
;; This file is not part of GNU Emacs. | ||
|
||
;; This program is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
;;; Commentary: | ||
|
||
;; Integration tests for `flycheck-rust-setup'. | ||
|
||
;;; Code: | ||
|
||
(require 'flycheck-rust) | ||
|
||
(buttercup-define-matcher :to-equal-one-of (elt &rest seq) | ||
(if (member elt seq) | ||
(cons t (format "Expected %S not to equal a member of %S" elt seq)) | ||
(cons nil (format "Expected %S to equal a member of %S" elt seq)))) | ||
|
||
(defun crate-file (file-name) | ||
(expand-file-name file-name "tests/test-crate")) | ||
|
||
(describe | ||
"`flycheck-rust-find-target' associates" | ||
|
||
(it "'src/lib.rs' to the library target" | ||
(expect | ||
(car (flycheck-rust-find-target (crate-file "src/lib.rs"))) | ||
:to-equal "lib")) | ||
|
||
(it "'src/a.rs' to the library target" | ||
(expect | ||
(car (flycheck-rust-find-target (crate-file "src/a.rs"))) | ||
:to-equal "lib")) | ||
|
||
(it "'src/main.rs' to the main binary target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "src/main.rs")) | ||
:to-equal '("bin" . "test-crate"))) | ||
|
||
(it "'src/bin/a.rs' to the 'a' binary target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "src/bin/a.rs")) | ||
:to-equal '("bin" . "a"))) | ||
|
||
(it "'src/bin/b.rs' to the 'b' binary target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "src/bin/b.rs")) | ||
:to-equal '("bin" . "b"))) | ||
|
||
(it "'src/bin/support/mod.rs' to the 'b' binary target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "src/bin/support/mod.rs")) | ||
:to-equal '("bin" . "b"))) | ||
|
||
(it "'tests/a.rs' to the 'a' test target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "tests/a.rs")) | ||
:to-equal '("test" . "a"))) | ||
|
||
(it "'tests/support/mod.rs' to any test target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "tests/support/mod.rs")) | ||
:to-equal-one-of '("test". "a") '("test". "b"))) | ||
|
||
(it "'examples/a.rs' to the 'a' example target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "examples/a.rs")) | ||
:to-equal '("example" . "a"))) | ||
|
||
(it "'examples/b.rs' to the 'b' example target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "examples/b.rs")) | ||
:to-equal '("example" . "b"))) | ||
|
||
(it "'examples/support/mod.rs' to any example target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "examples/support/mod.rs")) | ||
:to-equal-one-of '("example" . "a") '("example" . "b"))) | ||
|
||
(it "'benches/a.rs' to the 'a' bench target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "benches/a.rs")) | ||
:to-equal '("bench" . "a"))) | ||
|
||
(it "'benches/b.rs' to the 'b' bench target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "benches/b.rs")) | ||
:to-equal '("bench" . "b"))) | ||
|
||
(it "'benches/support/mod.rs' to any bench target" | ||
(expect | ||
(flycheck-rust-find-target (crate-file "benches/support/mod.rs")) | ||
:to-equal-one-of '("bench" . "a") '("bench" . "b"))) | ||
) |