Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 37 additions & 48 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
- 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
8 changes: 8 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* 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.
153 changes: 0 additions & 153 deletions Makefile

This file was deleted.

14 changes: 14 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
21 changes: 10 additions & 11 deletions rustic-babel.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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."))))
Expand All @@ -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")))
Expand Down
3 changes: 1 addition & 2 deletions rustic.el
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -30,7 +30,6 @@

(require 'cl-lib)
(require 'pcase)
(require 'seq)
(require 'subr-x)

(require 'dash)
Expand Down
9 changes: 9 additions & 0 deletions test/all-tests.el
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions test/rustic-babel-test.el
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Loading