Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pandoc-haskell-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
samhedin committed Jan 30, 2022
2 parents 524e3d0 + 63a6ba6 commit 0df1ad8
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/config.mk
*autoloads.el
.stack-work/
test/test-project/target
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ before being used.
- `rustic-cargo-bench` run 'cargo bench' for the current project
- `rustic-cargo-build-doc` build the documentation for the current project
- `rustic-cargo-doc` open the documentation for the current project in a browser
- `rustic-cargo-lints` called with `rustic-lints-arguments`

## Clippy

Expand Down
2 changes: 1 addition & 1 deletion rustic-babel.el
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ kill the running process."
(let ((default-directory dir)
(toolchain (cdr (assq :toolchain params))))
(write-region
(concat "#![allow(non_snake_case)]\n"
(concat "#![allow(non_snake_case, unused)]\n"
(if use-blocks (rustic-babel-insert-mod use-blocks) "")
(if include-blocks (rustic-babel-include-blocks include-blocks) "")
(if wrap-main (rustic-babel-ensure-main-wrap body) body))
Expand Down
53 changes: 30 additions & 23 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ If nil then the project is simply created."
:type 'boolean
:group 'rustic-cargo)

(defcustom rustic-default-test-arguments "--workspace --benches --tests --all-features"
"Default arguments when running 'cargo test'."
:type 'string
:group 'rustic-cargo)

(defcustom rustic-cargo-check-arguments "--workspace --benches --tests --all-features"
"Default arguments when running 'cargo check'."
:type 'string
Expand Down Expand Up @@ -90,6 +95,14 @@ stored in this variable.")
(when rustic-cargo-test-disable-warnings
(setq-local rustic-compile-rustflags "-Awarnings")))

(defun rustic-cargo-run-test (test)
"Run TEST which can be a single test or mod name."
(let* ((c (list (rustic-cargo-bin) "test" test))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
(mode 'rustic-cargo-test-mode))
(rustic-compilation c (list :buffer buf :process proc :mode mode))))

;;;###autoload
(defun rustic-cargo-test-run (&optional test-args)
"Start compilation process for 'cargo test' with optional TEST-ARGS."
Expand All @@ -112,10 +125,13 @@ When calling this function from `rustic-popup-mode', always use the value of
(interactive "P")
(rustic-cargo-test-run
(cond (arg
(setq rustic-test-arguments (read-from-minibuffer "Cargo test arguments: " rustic-test-arguments)))
(setq rustic-test-arguments (read-from-minibuffer "Cargo test arguments: " rustic-default-test-arguments)))
((eq major-mode 'rustic-popup-mode)
rustic-test-arguments)
(t ""))))
(if (> (length rustic-test-arguments) 0)
rustic-test-arguments
rustic-default-test-arguments))
(t
rustic-default-test-arguments))))

;;;###autoload
(defun rustic-cargo-test-rerun ()
Expand All @@ -141,15 +157,6 @@ When calling this function from `rustic-popup-mode', always use the value of
(rustic-cargo--get-current-mod)))
(rustic-cargo-test)))

(defun rustic-cargo-run-test (test)
"Run TEST which can be a single test or mod name."
(let* ((command (list (rustic-cargo-bin) "test" test))
(c (append command))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
(mode 'rustic-cargo-test-mode))
(rustic-compilation c (list :buffer buf :process proc :mode mode))))

(defconst rustic-cargo-mod-regexp
"^\s*mod\s+\\([[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*\\)\s*{")
(defconst rustic-cargo-fn-regexp
Expand Down Expand Up @@ -235,7 +242,7 @@ Execute process in PATH."
(inhibit-read-only t))
(make-process :name rustic-cargo-outdated-process-name
:buffer buf
:command '("cargo" "outdated" "--depth" "1")
:command `(,(rustic-cargo-bin) "outdated" "--depth" "1")
:filter #'rustic-cargo-outdated-filter
:sentinel #'rustic-cargo-outdated-sentinel
:file-handler t)
Expand Down Expand Up @@ -287,7 +294,7 @@ Execute process in PATH."
"Ask whether to install crate CRATE."
(let ((cmd (format "cargo install cargo-%s" crate)))
(when (yes-or-no-p (format "Cargo-%s missing. Install ? " crate))
(async-shell-command cmd "cargo" "cargo-error"))))
(async-shell-command cmd (rustic-cargo-bin) "cargo-error"))))

(defun rustic-cargo-outdated-generate-menu (packages)
"Re-populate the `tabulated-list-entries' with PACKAGES."
Expand Down Expand Up @@ -486,15 +493,15 @@ When calling this function from `rustic-popup-mode', always use the value of

(defun rustic-cargo-run-get-relative-example-name ()
"Run 'cargo run --example' if current buffer within a 'examples' directory."
(if rustic--buffer-workspace
(let ((relative-filenames
(split-string (file-relative-name buffer-file-name rustic--buffer-workspace) "/")))
(if (string= "examples" (car relative-filenames))
(let ((size (length relative-filenames)))
(cond ((eq size 2) (file-name-sans-extension(nth 1 relative-filenames))) ;; examples/single-example1.rs
((> size 2) (car (nthcdr (- size 2) relative-filenames))) ;; examples/example2/main.rs
(t nil))) nil))
nil))
(let* ((buffer-project-root (rustic-buffer-crate))
(relative-filenames
(if buffer-project-root
(split-string (file-relative-name buffer-file-name buffer-project-root) "/") nil)))
(if (and relative-filenames (string= "examples" (car relative-filenames)))
(let ((size (length relative-filenames)))
(cond ((eq size 2) (file-name-sans-extension (nth 1 relative-filenames))) ;; examples/single-example1.rs
((> size 2) (car (nthcdr (- size 2) relative-filenames))) ;; examples/example2/main.rs
(t nil))) nil)))

;;;###autoload
(defun rustic-run-shell-command (&optional arg)
Expand Down
19 changes: 18 additions & 1 deletion rustic-clippy.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
:type 'string
:group 'rustic-cargo)

(defcustom rustic-lints-arguments "-f custom_lints.toml clippy"
"Default arguments when running cargo-lints."
:type 'string
:group 'rustic-cargo)

(defvar rustic-clippy-process-name "rustic-cargo-clippy-process"
"Process name for clippy processes.")

Expand Down Expand Up @@ -53,6 +58,18 @@
:sentinel (plist-get args :sentinel)
:no-display (plist-get args :silent)))))

;;;###autoload
(defun rustic-cargo-lints ()
"Run cargo-lints with optional ARGS."
(interactive)
(let* ((command `(,(rustic-cargo-bin)
"lints"
,@(split-string rustic-lints-arguments)))
(buf rustic-clippy-buffer-name)
(proc rustic-clippy-process-name)
(mode 'rustic-cargo-clippy-mode))
(rustic-compilation command (list :buffer buf :process proc :mode mode))))

;;;###autoload
(defun rustic-cargo-clippy (&optional arg)
"Run 'cargo clippy'.
Expand All @@ -63,7 +80,7 @@ When calling this function from `rustic-popup-mode', always use the value of
(interactive "P")
(rustic-cargo-clippy-run
:params (cond (arg
(setq rustic-clippy-arguments (read-from-minibuffer "Cargo clippy arguments: " rustic-clippy-arguments)))
(setq rustic-clippy-arguments (read-from-minibuffer "Cargo clippy arguments: " rustic-default-clippy-arguments)))
((eq major-mode 'rustic-popup-mode)
(if (> (length rustic-clippy-arguments) 0)
rustic-clippy-arguments
Expand Down
5 changes: 4 additions & 1 deletion rustic-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ Set environment variables for rust process."
(set-process-sentinel process (plist-get args :sentinel))
(set-process-coding-system process 'utf-8-emacs-unix 'utf-8-emacs-unix)
(process-put process 'command (plist-get args :command))
(process-put process 'file-buffer (plist-get args :file-buffer))
process)))

(defun rustic-compilation-setup-buffer (buf dir mode &optional no-mode-line)
Expand Down Expand Up @@ -283,7 +284,8 @@ ARGS is a plist that affects how the process is run.
(process (or (plist-get args :process) rustic-compilation-process-name))
(mode (or (plist-get args :mode) 'rustic-compilation-mode))
(directory (or (plist-get args :directory) (funcall rustic-compile-directory-method)))
(sentinel (or (plist-get args :sentinel) #'compilation-sentinel)))
(sentinel (or (plist-get args :sentinel) #'compilation-sentinel))
(file-buffer (current-buffer)))
(rustic-compilation-setup-buffer buf directory mode)
(setq next-error-last-buffer buf)
(unless (plist-get args :no-display)
Expand All @@ -294,6 +296,7 @@ ARGS is a plist that affects how the process is run.
(rustic-make-process :name process
:buffer buf
:command command
:file-buffer file-buffer
:filter #'rustic-compilation-filter
:sentinel sentinel
:file-handler t))))
Expand Down
2 changes: 1 addition & 1 deletion rustic.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; rustic.el --- Rust development environment -*-lexical-binding: t-*-

;; Version: 2.5
;; Version: 2.6
;; Author: Mozilla
;;
;; Keywords: languages
Expand Down
24 changes: 24 additions & 0 deletions test/rustic-cargo-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,29 @@ fn test21() {
(buffer (process-buffer proc)))
(while (eq (process-status proc) 'run)
(sit-for 0.01))

(should (string= (s-join " " (process-get proc 'command))
(concat (rustic-cargo-bin) " check "
rustic-cargo-check-arguments)))

(with-current-buffer buffer
(should (string-match "^warning:\s" (buffer-substring-no-properties (point-min) (point-max)))))))))

(ert-deftest rustic-cargo-test-test ()
(let* ((string "mod tests {
#[test]
fn test() {
}
}")
(buf (rustic-test-count-error-helper-new string))
(default-directory (buffer-file-name buf)))
(with-current-buffer buf
(let* ((proc (rustic-cargo-test))
(buffer (process-buffer proc)))
(while (eq (process-status proc) 'run)
(sit-for 0.01))
(with-current-buffer buffer
(should (eq major-mode 'rustic-cargo-test-mode)))
(should (string= (s-join " " (process-get proc 'command))
(concat (rustic-cargo-bin) " test "
rustic-default-test-arguments)))))))
46 changes: 30 additions & 16 deletions test/rustic-compile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
(should (= compilation-num-errors-found 1))))))

(ert-deftest rustic-test-cargo-test ()
;; NOTE: this doesn't seem to be the case anymore
;; compilation-num-errors-found would be 8 with regular compilaton mode
;; due to parsing issues https://github.com/rust-lang/rust-mode/pull/254
(let ((rustic-compile-backtrace "full"))
Expand Down Expand Up @@ -209,19 +210,32 @@
(with-current-buffer (get-buffer rustic-test-buffer-name)
(should (= compilation-num-errors-found 10))))))

;; ;; TODO: parsing doesn't work
;; (ert-deftest rustic-test-count-warnings ()
;; (let* ((string "fn main() {
;; let v1 = vec![1, 2, 3];
;; let v2 = vec![1, 2, 3];
;; }")
;; (default-directory (rustic-test-count-error-helper string))
;; (proc (rustic-compilation-start (split-string "cargo build"))))
;; (while (eq (process-status proc) 'run)
;; (sit-for 0.1))
;; (with-current-buffer (get-buffer rustic-compilation-buffer-name)
;; (should (= compilation-num-warnings-found 1)))))




(ert-deftest rustic-test-count-warnings ()
(let* ((string "fn main() {
let v1 = vec![1, 2, 3];
let v2 = vec![1, 2, 3];
let v3 = vec![1, 2, 3];
let v4 = vec![1, 2, 3];
let v5 = vec![1, 2, 3];
let v6 = vec![1, 2, 3];
let v7 = vec![1, 2, 3];
let v8 = vec![1, 2, 3];
let v9 = vec![1, 2, 3];
let v10 = vec![1, 2, 3];
let v11 = vec![1, 2, 3];
let v12 = vec![1, 2, 3];
let v13 = vec![1, 2, 3];
let v14 = vec![1, 2, 3];
let v15 = vec![1, 2, 3];
let v16 = vec![1, 2, 3];
let v17 = vec![1, 2, 3];
let v18 = vec![1, 2, 3];
let v19 = vec![1, 2, 3];
let v20 = vec![1, 2, 3];
}")
(default-directory (rustic-test-count-error-helper string))
(proc (rustic-compilation-start (split-string "cargo build"))))
(while (eq (process-status proc) 'run)
(sit-for 0.1))
(with-current-buffer (get-buffer rustic-compilation-buffer-name)
(should (= compilation-num-warnings-found 20)))))
10 changes: 6 additions & 4 deletions test/rustic-workspace-test.el
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
;; -*- lexical-binding: t -*-
;; Before editing, eval (load-file "test-helper.el")

(ert-deftest rust-test-workspace-location ()
(ert-deftest rust-test-workspace-crate-location ()
(should (equal (funcall rustic-compile-directory-method) default-directory))
(let* ((test-workspace (expand-file-name "test/test-project/test-workspace/" default-directory))
(default-directory test-workspace))
(should (equal (funcall rustic-compile-directory-method) test-workspace))))
(let* ((test-workspace (expand-file-name "test/test-project/"))
(test-crate (expand-file-name "test/test-project/crates/test-crate/")))
(let ((default-directory (expand-file-name "src" test-crate)))
(should (string= (rustic-buffer-workspace) test-workspace))
(should (string= (rustic-buffer-crate) test-crate)))))

;; just test if project-root function works for different versions
(ert-deftest rust-test-project-root ()
Expand Down
7 changes: 7 additions & 0 deletions test/test-project/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/test-project/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Dummy file needed for test
[workspace]
members = ["crates/*"]
3 changes: 3 additions & 0 deletions test/test-project/crates/test-crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "test-workspace"
version = "0.0.1"
1 change: 1 addition & 0 deletions test/test-project/crates/test-crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uuse libc;
1 change: 0 additions & 1 deletion test/test-project/test-workspace/Cargo.toml

This file was deleted.

0 comments on commit 0df1ad8

Please sign in to comment.