Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Travis integration #61

Merged
merged 8 commits into from
Jul 19, 2017
Merged
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
11 changes: 11 additions & 0 deletions .emacs.d/init.el
Original file line number Diff line number Diff line change
@@ -3,6 +3,13 @@
;; Initialize the package repository.
(package-initialize)

;; Create variable to determine if we are in dev mode or not.
;; (Set this in your user hub.)
(defvar kotct/dev-mode
nil
"Whether or not kotct/dot emacs dev mode is enabled.
Makes tests runnable and other dev-only goodies.")


;;; Autoload Configuration
(setf generated-autoload-file "~/.emacs.d/lisp/kotct-loaddefs.el")
@@ -109,6 +116,10 @@ Despite this, your config appears to have loaded successfully.")
(if loaddefs-buffer
(kill-buffer loaddefs-buffer)))

;; If in dev mode, load the test runner.
(when kotct/dev-mode
(require 'dot-tests "~/.emacs.d/test/lisp/dot-tests"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to include this (both the var and the thing) in init.el because

  • It adds calls to the init stream under normal non-dev circumstances, and
  • Adding this to the source tree for the entire configuration means that we're tainting our actual configuration with testing stuff.

I think tests should be run in a separate Emacs instance from the existing one, if the developer is running one. The ability to run kotct/run-tests within the normal running circumstances is somewhat sketchy to me. Far better to run Emacs using a --script that also loads init than do this, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It adds calls to the init stream under normal non-dev circumstances

Hardly. I wouldn't consider a variable definition and an if-statement to be adding anything.

Adding this to the source tree for the entire configuration means that we're tainting our actual configuration with testing stuff.

I mean... the tests do not run or actually do anything unless you explicitly run them, so the only "tainting" is the definition of a few functions. Also this only happens in dev mode.

I think tests should be run in a separate Emacs instance from the existing one, if the developer is running one. The ability to run kotct/run-tests within the normal running circumstances is somewhat sketchy to me.

Officially, a separate Emacs instance is the correct way to run the tests. If emacs --script ~/.emacs.d/test/lisp/run-tests.el fails, the tests do not pass. That is how they're run in Travis. That said, having the ability to run the tests in your Emacs session is a convenience that makes it much easier to run/debug tests, and there's very little overhead.

Copy link
Member

@rye rye Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a good enough first step, I guess. We can go ahead and continue with the PR, and if it causes problems we can rethink.



;;; Customization File
;; We set this to something we don't track because it can be unique
1 change: 1 addition & 0 deletions .emacs.d/lisp/package/dependencies.el
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
web-mode ;; for editing web files
elixir-mode ;; for editing Elixir code
rust-mode ;; for editing Rust code
buttercup ;; for tests

;; THEMES
solarized-theme)
47 changes: 47 additions & 0 deletions .emacs.d/test/lisp/behavior/completion-c-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(kotct/load-corresponding)

(describe "completion config"
(describe "ido menu mode"
:var (orig-mode)

(before-all
; record original setting for later
(setf orig-mode kotct/ido-current-menu-mode))

(after-all
; restore original setting
(setf kotct/ido-current-menu-mode orig-mode))

(before-each
(spy-on #'ido-grid-mode)
(spy-on #'ido-vertical-mode))

(describe "is unset correctly"
(it "when using grid mode"
(let ((kotct/ido-current-menu-mode 'grid))
(kotct/ido-unset-menu-mode))

(expect #'ido-grid-mode :to-have-been-called)
(expect (spy-calls-args-for #'ido-grid-mode 0) :to-equal '(-1)))

(it "when using vertical mode"
(let ((kotct/ido-current-menu-mode 'vertical))
(kotct/ido-unset-menu-mode))

(expect #'ido-vertical-mode :to-have-been-called)
(expect (spy-calls-args-for #'ido-vertical-mode 0) :to-equal '(-1))))

(describe "is set correctly"
(it "to grid mode"
(let ((kotct/ido-current-menu-mode 'normal))
(kotct/ido-set-menu-mode 'grid))

(expect #'ido-grid-mode :to-have-been-called)
(expect (spy-calls-args-for #'ido-grid-mode 0) :to-equal '(+1)))

(it "to vertical mode"
(let ((kotct/ido-current-menu-mode 'normal))
(kotct/ido-set-menu-mode 'vertical))

(expect #'ido-vertical-mode :to-have-been-called)
(expect (spy-calls-args-for #'ido-vertical-mode 0) :to-equal '(+1))))))
45 changes: 45 additions & 0 deletions .emacs.d/test/lisp/dot-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(require 'buttercup)

(defun kotct/quietly-load-file (filename &optional throw-error)
"Load FILENAME, but do not send a message on success.
If loading throws an error, send a message with FILENAME and the error.
If THROW-ERROR is non-nil, re-throw the caught error."
(condition-case err
(load filename nil 'nomessage)
(error
(message (format "Error while loading %s:\n%s" file (error-message-string err)))
(if throw-error
(error (cdr err))))))

(defun kotct/load-corresponding ()
"Load the file corresponding to the current test.
Only works when called in script mode."
(when noninteractive
(assert (string-match-p "-test\\.el$" load-file-name))
(kotct/quietly-load-file
(replace-regexp-in-string
"-test\\.el$" ".el"
(replace-regexp-in-string
(regexp-quote "/test/") "/"
load-file-name)))))

(defun kotct/run-tests ()
"Run all emacs lisp tests for the kotct/dot emacs configuration."
(interactive)
(setf buttercup-suites nil)
(dolist (file (directory-files-recursively
(file-name-directory (symbol-file #'kotct/run-tests))
"-test\\.el\\'"))
(kotct/quietly-load-file file))
(let ((buttercup-reporter
(lambda (event arg)
(condition-case err
(buttercup-reporter-adaptive event arg)
(error
;; avoid error on test failure
(unless (and (not noninteractive)
(equal (second err) ""))
(error (second err))))))))
(buttercup-run)))

(provide 'dot-tests)
7 changes: 7 additions & 0 deletions .emacs.d/test/lisp/install.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(load-file "~/.emacs.d/lisp/package/dependencies.el")
(load-file "~/.emacs.d/lisp/package/repositories.el")

(package-initialize)
(package-refresh-contents)

(mapc #'package-install kotct/dependency-list)
7 changes: 7 additions & 0 deletions .emacs.d/test/lisp/run-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; NOTE: this file is designed to be exclusively run in script mode

(package-initialize)

(load-file (concat (file-name-directory load-file-name) "/dot-tests.el"))

(kotct/run-tests)
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: emacs-lisp
sudo: false
cache: apt
env:
- EVM_EMACS=emacs-25.1-travis
- EVM_EMACS=emacs-25.2-travis
- EVM_EMACS=emacs-git-snapshot-travis
before_install:
- git clone https://github.com/rejeep/evm.git ~/.evm
- export PATH="~/.evm/bin:$PATH"
- evm config path /tmp
install:
- evm install $EVM_EMACS --use --skip
- ln -s "$(pwd)/.emacs.d" ~/.emacs.d
- emacs --script .emacs.d/test/lisp/install.el
- echo "base-config" > .emacs.d/lisp/user/default-username
before_script:
- emacs --version
script:
- emacs --script .emacs.d/init.el
- emacs --script .emacs.d/test/lisp/run-tests.el
notifications:
slack:
secure: Pu2AagcBjx2iBPwsIJ3oNdB5koGfqSP12Mat9KYajxtIwbyzgGsToiyma3+s+Yl02+IRZdGonZaKH/c2RGNF05PK4PAoNfkhYafiog4hKD5ZusIi1xVr0zWOREZVsqpAeu0cxs/b+p7Va66+CRukGYxTGs0LjfEXoJ3KRJYwziSVDYVEoujGHFTPKlyNZNU0fSW+pioVneiVy+hpVvfdzqby9WJG9nK/607xceJ+HVdntXABnUBDk6/1KVqbH36U2Xlw2hlRebGWIowqg/S6yOqn+NxvrM5FNb7LHWxx/mLM3o5Ml1pm9mcDS0M+sPOquLlW/0NPfiV3cz485W6aoSo37z9eassQ4DKQsEjiL4AfGXH4Wgu3BASnWTMkSXfGwW09rKSu1PCyozp76htkiMWp2tJQo/GUAey7PYTSEHhFWBhBL2UaJ3WY4H/1SdaVqHwnBNXU6YEMIJn0S7F31MmQUmSIcVMbqP9XojWl9DHDKP9o4S5CCshYlKR3XzdSeOzyQKb2PKr5NAtU2lYVMfL4XYEsz+sWO1yOCUB+U0yVXdk9kInGHY5AAwIJ6v/ODSDGW67SlXMAJcrkW2nlX8I9JZ+aR4vKo47j+MCPsPMBaPoHyGquVe9++iq67Kdxl18azrQ6fVbjNda3LRTZVH9ekWRf9eMsVBbSeyORUx8=