Skip to content

Commit

Permalink
midje-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ljos committed Jan 4, 2014
1 parent 5fac1da commit 1527c4a
Show file tree
Hide file tree
Showing 5 changed files with 508 additions and 0 deletions.
38 changes: 38 additions & 0 deletions site-lisp/midje-mode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Overview

Midje-mode is an Emacs minor mode for
[Midje](https://github.com/marick/Midje) - test framework for Clojure,
which provides a migration path from clojure.test to a more flexible,
readable, abstract, and gracious style of testing.

See also wiki pages
[about midje-mode](https://github.com/marick/Midje/wiki/Midje-mode)
and [clojure-jump-to-file](https://github.com/marick/Midje/wiki/Clojure-jump-to-file).

# Install

Midje-mode can be installed through el-get: just add `midje-mode` to
your `el-get-sources`.

In addition, Midje-mode is on [marmalade-repo.org](http://marmalade-repo.org). Follow the
instructions on marmalade-repo.org to use the maramalde repo, then
install the midje-mode package.

Finally, you can download files manually
and place it somewhere on `load-path`, then add following lines to
your .emacs file:

(require 'midje-mode)
(require 'clojure-jump-to-file)

# Contributors

* Chris Bilson
* Ye He
* Andreas Liljeqvist
* Dave Kincaid
* Brian Marick
* Dmitri Naumov
* Steve Purcell
* Jani Rahkola
* "fmezas"
104 changes: 104 additions & 0 deletions site-lisp/midje-mode/clojure-jump-to-file.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
(require 'clojure-mode)
(require 'clojure-test-mode)

(defvar midje-root nil)
(defvar midje-filename-stash '())
(global-set-key "\^hj" 'midje-visit-source)

(defun midje-root (here)
"Set the root directory that."
(interactive "DProject Root Directory: ")
;; This wants to work in all buffers (or all shell buffers)?
(setq midje-root (expand-file-name here))
(setq midje-filename-stash '()))

(defun clojure-midje-test-for (namespace)
"Returns the path of the test file for the given namespace."
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(path (butlast (split-string namespace "\\.")))
(filename (concat "t_" (car (last (split-string namespace "\\."))))))
(format "%stest/%s.clj"
(file-name-as-directory
(locate-dominating-file buffer-file-name "src/"))
(mapconcat 'identity (append path (list filename)) "/"))))

(defun clojure-midje-implementation-for (namespace)
"Returns the path of the src file for the given test namespace."
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
(namespace-end (split-string (car (last segments)) "_"))
(filename (mapconcat 'identity (cdr namespace-end) "_"))
(impl-segments (append (butlast segments 1) (list filename))))
(format "%s/src/%s.clj"
(locate-dominating-file buffer-file-name "src/")
(mapconcat 'identity impl-segments "/"))))

(setq clojure-test-implementation-for-fn 'clojure-midje-implementation-for)

(setq clojure-test-for-fn 'clojure-midje-test-for)

(defun midje-visit-source ()
"If the current line contains text like '../src/program.clj:34', visit
that file in the other window and position point on that line."
(interactive)
(unless midje-root (call-interactively #'midje-root))
(let* ((start-boundary (save-excursion (beginning-of-line) (point)))
(regexp (concat "\\([ \t\n\r\"'([<{]\\|^\\)" ; non file chars or
; effective
; beginning of file
"\\(.+\\.clj\\):\\([0-9]+\\)" ; file.rb:NNN
"\\(\\+[0-9]\\)?"
))
(matchp (save-excursion
(end-of-line)
;; if two matches on line, the second is most likely
;; to be useful, so search backward.
(re-search-backward regexp start-boundary t))))

(if matchp
(let ((file (midje-match-part 2))
(line (midje-match-part 3))
(increment (midje-match-part 4)))
(midje-goto file line increment))
(error "No Clojure location on line."))))



(defun midje-reload-filename-stash (dir)
(setq midje-filename-stash
(split-string
(shell-command-to-string
(concat "find "
(shell-quote-argument dir)
" -name "
(shell-quote-argument "*.clj")
" -print "))))
nil)

(defun midje-matching-file (file)
(message (concat "Looking for this file: " file))
(let* ((regexp (concat "/" file "$")))
(find-if (lambda (fullpath) (string-match regexp fullpath))
midje-filename-stash))
)

(defun midje-goto (file line increment)
(let ((relevant-file (or (midje-matching-file file)
(midje-reload-filename-stash midje-root)
(midje-matching-file file))))
(message (concat "relevant file is " relevant-file))
(message increment)
(if (not relevant-file)
(error (concat "No Clojure file matches " file))
(find-file-other-window relevant-file)
(goto-line (string-to-int line))
(if increment
(search-forward "=>" nil nil (string-to-int increment)))))
)

(defun midje-match-part (n)
(if (match-beginning n)
(buffer-substring (match-beginning n) (match-end n))
nil))

(provide 'clojure-jump-to-file)
3 changes: 3 additions & 0 deletions site-lisp/midje-mode/midje-mode-pkg.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(define-package "midje-mode" "0.1.1"
"Minor mode for running Midje tests in emacs"
'((cider "0.1.4") (clojure-mode "1.0")))
54 changes: 54 additions & 0 deletions site-lisp/midje-mode/midje-mode-praise.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(defun midje-random-praise ()
(concat (nth (mod (random t) (length midje-praise-quotes))
midje-praise-quotes )
"\n"))

(defvar midje-praise-quotes
'(
"When someone asks you if you're a god, you say 'YES'! -- Zeddemore"
"The work itself praises the master. -- CPE Bach"
"Happiness comes when you believe that you have done something truly meaningful. -- Yan"
"I do believe in praising that which deserves to be praised. -- Dean Smith"
"Out of clutter find simplicity; from discord find harmony; in the middle of difficulty lies opportunity. -- Einstein"
"Satisfaction lies in the effort, not in the attainment, full effort is full victory. -- Gandhi"
"One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important. -- Russell"
"The sum of wisdom is that time is never lost that is devoted to work. -- Emerson"
"Without work, all life goes rotten. -- Camus"
"Work joyfully and peacefully, knowing that right thoughts and right efforts will inevitably bring about right results. -- Allen"
"Work is either fun or drudgery. It depends on your attitude. I like fun. -- Barrett"
"There's a certain satisfaction in a little bit of pain. -- Madonna"
"One small test for a codebase, one giant leap for quality kind! -- @zspencer"
"Hey! You're green! Refactor then we get to go red again! -- @zspencer"
"Woohoo! -- @zspencer"
"Ding! You Have Gained Experience -- @zspencer"
"A journey of a thousand miles begins with a single step. -- @alanmstokes"
"If this isn't nice, I don't know what is. -- Vonnegut"
"Simplicity, carried to the extreme, becomes elegance. -- Jon Franklin"
"This is the future you were hoping for. -- @Vaguery"
"O frabjous day! Callooh! Callay! -- Lewis Carroll"
"Whoever wants to reach a distant goal must take small steps. -- fortune cookie"
"The next function taunts you still. Will you rise to the challenge? -- anonymous"
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. -- Schumacher"
"Excellence is not an act but a habit. -- Aristotle"
"Code you'd be proud to give your mom to show off on the fridge. -- Mike Cohn"
"A clean boundary between useful abstractions and the grubby code that touches the real world is always a good thing. -- Ron Jeffries"
"Of course the universe *is* out to get us, but it's not going to do it by passing a null to one of our methods. -- Ron Jeffries"
"Good code is its own best documentation. -- Steve McConnell"
"First they ignored you, then they laughed at you, then they fought you, now you've won. -- Not quite Gandhi"
"The reward of a thing well done is to have done it. -- Emerson"
"The highest reward for a man's toil is not what he gets for it but what he becomes by it. -- Ruskin"
"Before the reward there must be labor. You plant before you harvest. You sow in tears before you reap joy. -- Ransom"
"Intellectual 'work' is misnamed; it is a pleasure, a dissipation, and is its own highest reward. -- Twain"
"The biggest reward for a thing well done is to have done it. -- Voltaire"
"Effort only fully releases its reward after a person refuses to quit. -- Hill"
"The journey is the reward. -- traditional"
"For every disciplined effort, there is a multiple reward. -- Rohn"
"Happiness is not a reward / it is a consequence. -- Ingersoll"
"It takes time to succeed because success is merely the natural reward of taking time to do anything well. -- Ross"
"There is an inevitable reward for good deeds. -- Ming Fu Wu"
"Achievement is its own reward. -- David Lynch"
"Not in rewards, but in the strength to strive, the blessing lies. -- Towbridge"
"The right word may be effective, but no word was ever as effective as a rightly timed pause. -- Twain"
))

(provide 'midje-mode-praise)
Loading

0 comments on commit 1527c4a

Please sign in to comment.