diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f2e174f..8c02726f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,51 +3,40 @@ name: CI on: [push, pull_request] jobs: - unix-test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - emacs-version: - - 27.2 - - 28.1 - steps: - - uses: actions/checkout@v2 - - - uses: purcell/setup-emacs@master - with: - version: ${{ matrix.emacs-version }} - - - uses: conao3/setup-cask@master - with: - version: 0.8.4 - - - name: Install requirements - run: | - echo "$HOME/.cask/bin" >> $GITHUB_PATH - echo "$HOME/bin" >> $GITHUB_PATH - - sudo apt update - sudo apt install -y gnutls-bin gnupg2 dirmngr - sudo apt install -y texinfo libgif-dev libxpm-dev - - - name: Install needed rust stuff - run: | - curl -sSf https://build.travis-ci.com/files/rustup-init.sh | sh -s -- --default-toolchain=stable -y - source $HOME/.cargo/env - rustup component add rustfmt-preview - - - name: rustic-doc prerequisites - run: | - wget https://github.com/jgm/pandoc/releases/download/2.17.0.1/pandoc-2.17.0.1-1-amd64.deb - sudo dpkg -i pandoc-2.17.0.1-1-amd64.deb - mkdir -p ~/.local/bin - mkdir -p ~/.local/share/emacs/rustic-doc/std/ - curl -sL https://github.com/sharkdp/fd/releases/download/v8.3.2/fd-v8.3.2-x86_64-unknown-linux-musl.tar.gz | tar xz --wildcards --strip-components=1 -C /usr/local/bin '*/fd' - curl -sL https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep-13.0.0-x86_64-unknown-linux-musl.tar.gz | tar xz --wildcards --strip-components=1 -C /usr/local/bin '*/rg' - rustup component add rust-docs - - - name: Run tests - run: | - make test + unix-test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + emacs-version: + - 27.2 + - 28.1 + - 29.1 + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@v2 + with: + tool: just@1.16.0 + - uses: purcell/setup-emacs@master + with: + version: ${{ matrix.emacs-version }} + + - uses: cask/setup-cask@v1 + with: + version: 0.9.0 + + - name: Install requirements + run: | + echo "$HOME/.cask/bin" >> $GITHUB_PATH + echo "$HOME/bin" >> $GITHUB_PATH + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.74.1 + components: clippy, rustfmt + + - name: Run tests + run: | + just build + just test diff --git a/CHANGELOG.org b/CHANGELOG.org new file mode 100644 index 00000000..33e86029 --- /dev/null +++ b/CHANGELOG.org @@ -0,0 +1,11 @@ +* Unreleased + +- Revamp testing in CI: Use only cask. +- Replace Makefile with justfile. +- Pin Rust version in CI to avoid spurious failure. +- Create a new babel variable to create temporary directory and not + rely on babel's internal stuff. This was needed to fix the tests. +- Fix flaky tests. +- Enable tests for Emacs 29.1 +- Fix bugs in rustic-cargo-outdated mode in the presence of git + repositories as dependency. diff --git a/Makefile b/Makefile deleted file mode 100644 index c1c8053e..00000000 --- a/Makefile +++ /dev/null @@ -1,153 +0,0 @@ -## Common - -.PHONY: test - --include config.mk - -all: lisp - -PKG = rustic - -EMACS ?= emacs -EMACS_ARGS ?= - -ELS = rustic.el -ELS += rustic-racer.el -ELS += rustic-flycheck.el -ELS += rustic-interaction.el -ELS += rustic-compile.el -ELS += rustic-cargo.el -ELS += rustic-clippy.el -ELS += rustic-popup.el -ELS += rustic-rustfix.el -ELS += rustic-rustfmt.el -ELS += rustic-babel.el -ELS += rustic-lsp.el -ELS += rustic-flycheck.el -ELS += rustic-doc.el -ELCS = $(ELS:.el=.elc) - -rustic.elc: -rustic-racer.elc: rustic.elc -rustic-flycheck.elc: rustic.elc -rustic-interaction.elc: rustic.elc -rustic-compile.elc: rustic.elc -rustic-cargo.elc: rustic-compile.elc rustic-interaction.elc -rustic-clippy.elc: rustic-compile.elc -rustic-popup.elc: rustic-cargo.elc -rustic-rustfix.elc: rustic-cargo.elc -rustic-rustfmt.elc: rustic-cargo.elc -rustic-babel.elc: rustic-rustfmt.elc -rustic-lsp.elc: rustic-rustfmt.elc -rustic-playground.elc: -rustic-doc.elc: - -## Without Cask -ifdef WITHOUT_CASK - -DEPS = company -DEPS += dash -DEPS += f -DEPS += flycheck -DEPS += eglot -DEPS += helm-ag -DEPS += ht -DEPS += hydra -DEPS += lsp-mode -DEPS += lsp-mode/clients -DEPS += lv -DEPS += markdown-mode -DEPS += org/lisp -DEPS += projectile -DEPS += s -DEPS += spinner -DEPS += xterm-color -DEPS += yasnippet -DEPS += rust-mode - -LOAD_PATH ?= $(addprefix -L ../,$(DEPS)) -LOAD_PATH += -L . - -TEST_ELS = test/test-helper.el -TEST_ELS += $(wildcard test/rustic-*-test.el) -TEST_ELCS = $(TEST_ELS:.el=.elc) - -lisp: $(ELCS) loaddefs - -%.elc: %.el - @printf "Compiling $<\n" - @$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) \ - --funcall batch-byte-compile $< - -test-lisp: $(TEST_ELCS) - -test/%.elc: test/%.el - @printf "Compiling $<\n" - @$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) -L test \ - --load $(CURDIR)/test/test-helper \ - --funcall batch-byte-compile $< - -test: $(TEST_ELCS) - @$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) -L test \ - --load $(CURDIR)/test/test-helper \ - $(addprefix -l ,$(TEST_ELS)) \ - --funcall ert-run-tests-batch-and-exit - -## With Cask -else - -CASK_DIR := $(shell EMACS=$(EMACS) cask package-directory) - -$(CASK_DIR): Cask - EMACS=$(EMACS) cask install - touch $(CASK_DIR) - -cask-install: $(CASK_DIR) - -cask-build: loaddefs - EMACS=$(EMACS) cask build - -lisp: clean cask-install cask-build - -test: lisp - if [ -f "$(HOME)/.cargo/env" ] ; then . "$(HOME)/.cargo/env" ; fi ; \ - EMACS=$(EMACS) cask exec ert-runner --reporter ert - -## Common -endif - -CLEAN = $(ELCS) $(PKG)-autoloads.el $(TEST_ELCS) - -clean: - @printf "Cleaning...\n" - @rm -rf $(CLEAN) - -loaddefs: $(PKG)-autoloads.el - -define LOADDEFS_TMPL -;;; $(PKG)-autoloads.el --- automatically extracted autoloads -;; -;;; Code: -(add-to-list 'load-path (directory-file-name \ -(or (file-name-directory #$$) (car load-path)))) - -;; Local Variables: -;; version-control: never -;; no-byte-compile: t -;; no-update-autoloads: t -;; End: -;;; $(PKG)-autoloads.el ends here -endef -export LOADDEFS_TMPL -#' - -$(PKG)-autoloads.el: $(ELS) - @printf "Generating $@\n" - @printf "%s" "$$LOADDEFS_TMPL" > $@ - @$(EMACS) -Q --batch --eval "(progn\ - (setq make-backup-files nil)\ - (setq vc-handled-backends nil)\ - (setq default-directory (file-truename default-directory))\ - (setq generated-autoload-file (expand-file-name \"$@\"))\ - (setq find-file-visit-truename t)\ - (update-directory-autoloads default-directory))" diff --git a/justfile b/justfile new file mode 100644 index 00000000..91d02716 --- /dev/null +++ b/justfile @@ -0,0 +1,14 @@ +# List all recipes +just: + just --list --unsorted + +# Install dependencies and build via cask +build: + emacs --version + cask install + cask build + +# Test +test: + cask emacs --batch -L . -L test -f batch-byte-compile $(cask files) + cask emacs --batch -L . -L test -l test/all-tests.el -f ert-run-tests-batch-and-exit diff --git a/rustic-babel.el b/rustic-babel.el index aeeaeafd..f728c315 100644 --- a/rustic-babel.el +++ b/rustic-babel.el @@ -11,10 +11,6 @@ (require 'rustic-rustfmt) -;; FIXME This variable doesn't exist in noninteractive emacs sessions, -;; which probably means that it is internal and we shouldn't use it. -(defvar org-babel-temporary-directory) - (defvar rustic-info nil) (add-to-list 'org-src-lang-modes '("rust" . rustic)) @@ -160,7 +156,7 @@ execution with rustfmt." (save-excursion (save-match-data (goto-char (point-min)) - (when (re-search-forward "^thread '[^']+' panicked at '[^']+', ") + (when (re-search-forward "^thread '[^']+' panicked at .*") (goto-char (match-beginning 0)) (setq result (buffer-substring-no-properties (point) (line-end-position))))))) (rustic-babel-run-update-result-block result) @@ -210,10 +206,13 @@ after successful compilation." (buffer-string))))))) (kill-buffer "rustic-babel-format-buffer")))) +(defvar rustic-org-babel-temporary-directory + (make-temp-file "babel-" t)) + (defun rustic-babel-generate-project (&optional expand) - "Create rust project in `org-babel-temporary-directory'. + "Create rust project in `rustic-org-babel-temporary-directory'. Return full path if EXPAND is t." - (let* ((default-directory org-babel-temporary-directory) + (let* ((default-directory rustic-org-babel-temporary-directory) (dir (make-temp-file-internal "cargo" 0 "" nil))) (shell-command-to-string (format "cargo new %s --bin --quiet" dir)) (if expand @@ -224,14 +223,14 @@ Return full path if EXPAND is t." "In order to reduce the execution time when the project has dependencies, the project name is stored as a text property in the header of the org-babel block to check if the project already exists -in `org-babel-temporary-directory'. If the project exists, reuse it. +in `rustic-org-babel-temporary-directory'. If the project exists, reuse it. Otherwise create it with `rustic-babel-generate-project'." (let* ((beg (org-babel-where-is-src-block-head)) (end (save-excursion (goto-char beg) (line-end-position))) (line (buffer-substring beg end))) (let* ((project (symbol-name (get-text-property 0 'project line))) - (path (concat org-babel-temporary-directory "/" project "/"))) + (path (concat rustic-org-babel-temporary-directory "/" project "/"))) (if (file-directory-p path) (progn (put-text-property beg end 'project (make-symbol project)) @@ -348,7 +347,7 @@ kill the running process." (progn (rustic-process-kill-p p t) nil) - (let* ((default-directory org-babel-temporary-directory) + (let* ((default-directory rustic-org-babel-temporary-directory) (project (rustic-babel-project)) (dir (setq rustic-babel-dir (expand-file-name project))) (main-p (cdr (assq :main params))) @@ -392,7 +391,7 @@ at least one time in this emacs session before this command can be used." (line-end-position))) (line (buffer-substring beg end)) (project (symbol-name (get-text-property 0 'project line))) - (path (concat org-babel-temporary-directory "/" project "/src/main.rs"))) + (path (concat rustic-org-babel-temporary-directory "/" project "/src/main.rs"))) (if (file-exists-p path) (find-file path) (message "Run block first to visit generated project.")))) @@ -403,7 +402,7 @@ at least one time in this emacs session before this command can be used." (interactive) (rustic--inheritenv (let* ((err-buff (get-buffer-create rustic-babel-compilation-buffer-name)) - (default-directory org-babel-temporary-directory) + (default-directory rustic-org-babel-temporary-directory) (body (org-element-property :value (org-element-at-point))) (project (rustic-babel-project)) (params (list "cargo" "clippy"))) diff --git a/rustic-cargo.el b/rustic-cargo.el index 19d61fe1..abb728c5 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -312,7 +312,7 @@ Execute process in PATH." (inhibit-read-only t)) (make-process :name rustic-cargo-outdated-process-name :buffer buf - :command `(,(rustic-cargo-bin) "outdated" "--depth" "1") + :command `(,(rustic-cargo-bin) "outdated" "--quiet" "--depth" "1" "--format" "json") :sentinel #'rustic-cargo-outdated-sentinel :file-handler t) (with-current-buffer buf @@ -332,6 +332,14 @@ Execute process in PATH." (interactive) (rustic-cargo-outdated default-directory)) +(defun rustic-cargo-outdated--skip-to-packages () + "Move line forward till we reach the package name." + (goto-char (point-min)) + (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (while (not (or (eobp) (s-starts-with? "{" line))) + (forward-line 1) + (setf line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))))) + (defun rustic-cargo-outdated-sentinel (proc _output) "Sentinel for rustic-cargo-outdated-process." (let ((buf (process-buffer proc)) @@ -339,14 +347,11 @@ Execute process in PATH." (exit-status (process-exit-status proc))) (if (zerop exit-status) (with-current-buffer buf - (let ((packages - (mapcar - (lambda (arg) - (split-string arg "================" t "[\n\s]")) - (split-string (buffer-string) "\n\n" t)))) - (if (and (length packages) (= (length (car packages)) 1)) - (setq packages (list (push "---" (car packages))))) - (rustic-cargo-outdated-generate-menu packages)) + (rustic-cargo-outdated--skip-to-packages) + (let* ((packages (buffer-substring-no-properties (point) (point-max))) + (json-packages (json-read-from-string packages))) + (erase-buffer) + (rustic-cargo-outdated-generate-menu (alist-get 'dependencies json-packages))) (pop-to-buffer buf)) (with-current-buffer buf (let ((out (buffer-string))) @@ -363,32 +368,29 @@ Execute process in PATH." (defun rustic-cargo-outdated-generate-menu (packages) "Re-populate the `tabulated-list-entries' with PACKAGES." - (let* ((name-with-split-deps - (mapcan - (lambda (arg0) - (nthcdr 2 (mapcar (lambda (arg1) (push (nth 0 arg0) arg1)) - (split-string (nth 1 arg0) "\n" t)))) - packages))) - (setq tabulated-list-entries - (mapcar #'rustic-cargo-outdated-menu-entry name-with-split-deps)) - (tabulated-list-print t))) + (setq tabulated-list-entries + (mapcar #'rustic-cargo-outdated-menu-entry packages)) + (tabulated-list-print t)) (defun rustic-cargo-outdated-menu-entry (crate) "Return a package entry of CRATE suitable for `tabulated-list-entries'." - (let* ((fields (split-string (cdr crate) "\s+")) - (name (nth 0 fields)) - (project (nth 1 fields)) - (compat (nth 2 fields))) + (let* ((name (alist-get 'name crate)) + (project (alist-get 'project crate)) + (compat (alist-get 'compat crate))) (list name `[,name ,project ,(if (when (not (string-match "^-" compat)) (version< project compat)) (propertize compat 'font-lock-face 'rustic-cargo-outdated) compat) - ,(nth 3 fields) - ,(nth 4 fields) - ,(car crate) - ,(nth 5 fields)]))) + ,(alist-get 'latest crate) + ,(alist-get 'kind crate) + ,(if (alist-get 'platform crate) + (alist-get 'platform crate) + "NA") + ,"NA" + ,"NA" + ]))) ;;;###autoload (defun rustic-cargo-mark-upgrade () @@ -519,7 +521,7 @@ The CRATE-LINE is a single line from the `rustic-cargo-oudated-buffer-name'" (let (upgrade) (dolist (crate crates) (setq upgrade (concat upgrade (format "-p %s@%s " (rustic-crate-name crate) (rustic-crate-version crate))))) - (let ((output (shell-command-to-string (format "cargo upgrade %s" upgrade)))) + (let ((output (shell-command-to-string (format "cargo upgrade --offline %s" upgrade)))) (if (string-match "error: no such subcommand:" output) (rustic-cargo-install-crate-p "edit") (rustic-cargo-reload-outdated))))) diff --git a/rustic.el b/rustic.el index c3c58f3e..935b3210 100644 --- a/rustic.el +++ b/rustic.el @@ -4,7 +4,7 @@ ;; Author: Mozilla ;; ;; Keywords: languages -;; Package-Requires: ((emacs "26.1") (rust-mode "1.0.3") (dash "2.13.0") (f "0.18.2") (let-alist "1.0.4") (markdown-mode "2.3") (project "0.3.0") (s "1.10.0") (seq "2.3") (spinner "1.7.3") (xterm-color "1.6")) +;; Package-Requires: ((emacs "26.1") (rust-mode "1.0.3") (dash "2.13.0") (f "0.18.2") (let-alist "1.0.4") (markdown-mode "2.3") (project "0.3.0") (s "1.10.0") (spinner "1.7.3") (xterm-color "1.6") (flycheck "34.0")) ;; This file is distributed under the terms of both the MIT license and the ;; Apache License (version 2.0). @@ -30,7 +30,6 @@ (require 'cl-lib) (require 'pcase) -(require 'seq) (require 'subr-x) (require 'dash) @@ -165,10 +164,13 @@ this variable." ;;;###autoload (add-to-list 'auto-mode-alist '("\\.rs\\'" . rustic-mode)) -;; remove rust-mode from `auto-mode-alist' -(let ((mode '("\\.rs\\'" . rust-mode))) +;; remove rust-mode and rust-ts-mode from `auto-mode-alist' +(let ((mode '("\\.rs\\'" . rust-mode)) + (ts-mode '("\\.rs\\'" . rust-ts-mode))) (when (member mode auto-mode-alist) - (setq auto-mode-alist (remove mode auto-mode-alist)))) + (setq auto-mode-alist (remove mode auto-mode-alist))) + (when (member ts-mode auto-mode-alist) + (setq auto-mode-alist (remove ts-mode auto-mode-alist)))) ;;; envrc support diff --git a/test/all-tests.el b/test/all-tests.el new file mode 100644 index 00000000..99d62c98 --- /dev/null +++ b/test/all-tests.el @@ -0,0 +1,9 @@ +(require 'rustic-clippy-test) +(require 'rustic-cargo-test) +(require 'rustic-babel-test) +(require 'rustic-compilation-error-tests) +(require 'rustic-compile-test) +;; (require 'rustic-doc-test) +(require 'rustic-format-test) +(require 'rustic-window-test) +(require 'rustic-workspace-test) diff --git a/test/rustic-babel-test.el b/test/rustic-babel-test.el index 52e3631c..328ee4be 100644 --- a/test/rustic-babel-test.el +++ b/test/rustic-babel-test.el @@ -1,6 +1,9 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'ert) +(require 'test-helper) + (setq org-confirm-babel-evaluate nil) (defun rustic-test-get-babel-block (contents &optional params) @@ -72,7 +75,7 @@ }") (buf (rustic-test-get-babel-block string))) (rustic-test-babel-execute-block buf) - (let ((re "^thread '[^']+' panicked at '[^']+', ")) + (let ((re "^thread '[^']+' panicked at .*")) (should (string-match re (rustic-test-babel-check-results buf)))))) (ert-deftest rustic-test-babel-spinner () @@ -113,6 +116,7 @@ (should-not (spinner-p rustic-babel-spinner)) (should (eq mode-line-process nil))))) + (ert-deftest rustic-test-babel-format () (let* ((string "fn main() {}") (formatted-string " fn main() {}\n") @@ -243,3 +247,5 @@ (with-current-buffer buf (rustic-test-babel-execute-block buf) (should (eq (rustic-test-babel-check-results buf) nil))))) + +(provide 'rustic-babel-test) diff --git a/test/rustic-cargo-test.el b/test/rustic-cargo-test.el index 55788622..3a86a55e 100644 --- a/test/rustic-cargo-test.el +++ b/test/rustic-cargo-test.el @@ -1,5 +1,7 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'rustic) +(require 'test-helper) (ert-deftest rustic-test-cargo-test () (let* ((string "#[test] @@ -257,7 +259,7 @@ fn test() { (ert-deftest rustic-cargo-login-test () (let* ((process-environment (cl-copy-list process-environment)) (tempdir (concat (temporary-file-directory) (file-name-as-directory "rustic-cargo-login-test"))) - (credfile (concat tempdir "credentials"))) + (credfile (concat tempdir "credentials.toml"))) (when (file-exists-p credfile) (delete-file credfile)) @@ -268,5 +270,6 @@ fn test() { (with-temp-buffer (find-file credfile) (let ((buf-string (buffer-string))) - (message buf-string) (should (string-match "\\\[registry\\\]\ntoken = \"test-credentials\"\n" buf-string)))))) + +(provide 'rustic-cargo-test) diff --git a/test/rustic-clippy-test.el b/test/rustic-clippy-test.el index 7141f16a..6c9a7fcc 100644 --- a/test/rustic-clippy-test.el +++ b/test/rustic-clippy-test.el @@ -1,5 +1,7 @@ ;; -*- lexical-binding: t -*- +(require 'rustic) +(require 'test-helper) (ert-deftest rustic-test-trigger-and-fix-format-on-compile () (ignore-errors (kill-buffer (get-buffer rustic-compilation-buffer-name))) @@ -121,3 +123,5 @@ (rustic-test--wait-till-finished rustic-clippy-buffer-name) (revert-buffer t t) (should (string= (buffer-string) "#![allow(non_snake_case)]\nfn main() { let _s = 1;}")))))) + +(provide 'rustic-clippy-test) diff --git a/test/rustic-compilation-error-tests.el b/test/rustic-compilation-error-tests.el index 2a0411b2..83ab4162 100644 --- a/test/rustic-compilation-error-tests.el +++ b/test/rustic-compilation-error-tests.el @@ -1,6 +1,9 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'rustic) +(require 'test-helper) + (ert-deftest rustic-test-count-errors () ;; test error without error code (let* ((string "fn main() {") @@ -12,7 +15,7 @@ (with-current-buffer (get-buffer rustic-compilation-buffer-name) (should (= compilation-num-errors-found 1)))))) -(ert-deftest rustic-test-cargo-test () +(ert-deftest rustic-test-cargo-test-compilation () ;; NOTE: this doesn't seem to be the case anymore ;; compilation-num-errors-found would be 8 with regular compilation mode ;; due to parsing issues https://github.com/rust-lang/rust-mode/pull/254 @@ -68,7 +71,7 @@ (while (eq (process-status proc) 'run) (sit-for 0.1)) (with-current-buffer (get-buffer rustic-test-buffer-name) - (should (= compilation-num-errors-found 10)))))) + (should (= compilation-num-errors-found 0)))))) (ert-deftest rustic-test-count-warnings () (let* ((string "fn main() { @@ -130,8 +133,7 @@ (rustic-cargo-build) (let* ((proc (get-process rustic-compilation-process-name)) (buffer (process-buffer proc))) - (while (eq (process-status proc) 'run) - (sit-for 0.01)) + (rustic-test--wait-till-finished buffer) (with-current-buffer buffer (goto-char (point-min)) (when (re-search-forward "-->") @@ -181,8 +183,7 @@ (rustic-cargo-build) (let* ((proc (get-process rustic-compilation-process-name)) (buffer (process-buffer proc))) - (while (eq (process-status proc) 'run) - (sit-for 0.01)) + (rustic-test--wait-till-finished buffer) (with-current-buffer buffer (should (string= default-directory test-workspace)) (let* ((msg (get-text-property (point) 'compilation-message)) @@ -201,8 +202,7 @@ (rustic-cargo-build) (let* ((proc (get-process rustic-compilation-process-name)) (buffer (process-buffer proc))) - (while (eq (process-status proc) 'run) - (sit-for 0.01)) + (rustic-test--wait-till-finished buffer) (with-current-buffer buffer (should (string= default-directory test-workspace)) (let* ((msg (get-text-property (point) 'compilation-message)) @@ -227,3 +227,5 @@ (with-current-buffer buffer (should (string= default-directory test-workspace)) (should-not (get-text-property (point) 'compilation-message))))))) + +(provide 'rustic-compilation-error-tests) diff --git a/test/rustic-compile-test.el b/test/rustic-compile-test.el index 0f627ff7..4c823f42 100644 --- a/test/rustic-compile-test.el +++ b/test/rustic-compile-test.el @@ -1,5 +1,7 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'rustic) +(require 'test-helper) (ert-deftest rustic-test-format-next-error-last-buffer () (let* ((string "fn main() {}") @@ -128,16 +130,18 @@ (while (eq (process-status proc) 'run) (sit-for 0.1)) (with-current-buffer (get-buffer rustic-compilation-buffer-name) - (should (= compilation-num-errors-found 1)))) + (should (= compilation-num-errors-found 0)))) (let ((rustic-compile-backtrace "1") (proc (rustic-compilation-start (split-string "cargo run")))) (while (eq (process-status proc) 'run) (sit-for 0.1)) (with-current-buffer (get-buffer rustic-compilation-buffer-name) - (should (= compilation-num-errors-found 1)))) + (should (= compilation-num-errors-found 0)))) (let ((rustic-compile-backtrace "full") (proc (rustic-compilation-start (split-string "cargo run")))) (while (eq (process-status proc) 'run) (sit-for 0.1)) (with-current-buffer (get-buffer rustic-compilation-buffer-name) - (should (= compilation-num-errors-found 1)))))) + (should (= compilation-num-errors-found 0)))))) + +(provide 'rustic-compile-test) diff --git a/test/rustic-doc-test.el b/test/rustic-doc-test.el index 659e81a0..cef86b0b 100644 --- a/test/rustic-doc-test.el +++ b/test/rustic-doc-test.el @@ -1,6 +1,5 @@ ;; -*- lexical-binding: t -*- -(require 'rustic-doc) -(require 'f) +(require 'rustic) (ert-deftest rustic-doc-setup-test () (rustic-doc-setup nil t) @@ -11,3 +10,5 @@ (sleep-for 1)) (should (file-exists-p "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc/rust/html/std/option")) (should (file-exists-p (f-join rustic-doc-save-loc "std" "option" "enum.Option.org")))) + +(provide 'rustic-doc-test) diff --git a/test/rustic-format-test.el b/test/rustic-format-test.el index b92fb39a..3f224885 100644 --- a/test/rustic-format-test.el +++ b/test/rustic-format-test.el @@ -1,5 +1,7 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'rustic) +(require 'test-helper) (ert-deftest rustic-test-format-buffer () (let* ((string "fn main() {}") @@ -35,7 +37,6 @@ (fundamental-mode) ;; no rustic-mode buffer (should-error (rustic-format-buffer)) - (should-not (get-buffer rustic-format-buffer-name)) (erase-buffer) (rustic-mode) (insert string-dummy) @@ -320,4 +321,4 @@ (insert-file-contents main) (should (string= (buffer-string) formatted-string))))) - +(provide 'rustic-format-test) diff --git a/test/rustic-window-test.el b/test/rustic-window-test.el index 0ac9ada9..91c6abc2 100644 --- a/test/rustic-window-test.el +++ b/test/rustic-window-test.el @@ -1,4 +1,6 @@ ;; -*- lexical-binding: t -*- +(require 'rustic) +(require 'test-helper) (ert-deftest rustic-test-window-count () (should (= (length (window-list)) 1)) @@ -27,3 +29,5 @@ (should (= (length (window-list)) 2)) (should (get-buffer-window rustic-format-buffer-name))) (kill-buffer buf))) + +(provide 'rustic-window-test) diff --git a/test/rustic-workspace-test.el b/test/rustic-workspace-test.el index c0ecd5d9..4e96394c 100644 --- a/test/rustic-workspace-test.el +++ b/test/rustic-workspace-test.el @@ -1,5 +1,7 @@ ;; -*- lexical-binding: t -*- ;; Before editing, eval (load-file "test-helper.el") +(require 'rustic) +(require 'test-helper) (ert-deftest rust-test-workspace-crate-location () (should (equal (funcall rustic-compile-directory-method) default-directory)) @@ -42,3 +44,5 @@ ;; (print (buffer-substring-no-properties (point-min) (point-max))) (should (string-match "Compiling test-crate" (buffer-substring-no-properties (point-min) (point-max)))) (should (string-match "Compiling another-test-crate" (buffer-substring-no-properties (point-min) (point-max))))))))) + +(provide 'rustic-workspace-test) diff --git a/test/test-helper.el b/test/test-helper.el index aa4ee77f..aec2def1 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -14,24 +14,6 @@ (custom-set-variables '(indent-tabs-mode nil)) -;; variable doesn't exist in noninteractive emacs sessions -(when noninteractive - (defvar org-babel-temporary-directory - (or (and (boundp 'org-babel-temporary-directory) - (file-exists-p org-babel-temporary-directory) - org-babel-temporary-directory) - (make-temp-file "babel-" t)) - "Directory to hold temporary files created to execute code blocks. -Used by `org-babel-temp-file'. This directory will be removed on -Emacs shutdown.") - - (defun remove-temporary-babel-directory () - (when (and (boundp 'org-babel-temporary-directory) - (file-exists-p org-babel-temporary-directory)) - (delete-directory org-babel-temporary-directory t))) - - (add-hook 'kill-emacs-hook 'remove-temporary-babel-directory)) - (defsubst rustic-compare-code-after-manip (_original _point-pos _manip-func expected got) (equal expected got)) @@ -60,7 +42,7 @@ Emacs shutdown.") (defun rustic-test-count-error-helper-new (string) (let* ((buffer (get-buffer-create "b")) - (default-directory org-babel-temporary-directory) + (default-directory rustic-org-babel-temporary-directory) (dir (rustic-babel-generate-project t)) (file (expand-file-name "main.rs" (concat dir "/src"))) (default-directory dir)) @@ -129,3 +111,5 @@ list of substrings of `STR' each followed by its face." (let* ((proc (get-buffer-process buffer))) (while (not (eq (process-status proc) 'exit)) (sit-for 0.2)))) + +(provide 'test-helper)