-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite indentation testing code (#26)
Benefits of new solution: 1. Faster (runs indentation tests in parallel) - On GitHub Actions, the tests now finish >10 seconds quicker, but we will see a greater benefit when I add more indentation tests (hopefully soon). 2. Less code 3. Adding new indentation test cases doesn't require editing the indent_test.clj Clojure file anymore 4. Fixed issues with the test vimrc so tests now work on newer Vim versions (previously they only worked on Vim 8.1 and below) 5. Can now set different config options per-test 6. Indentation tests now all pass on my computer Now we're in a good position to start adding more indentation tests.
- Loading branch information
Showing
22 changed files
with
94 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
{:lint-as {vim.test/with-tempfile clojure.core/fn | ||
vim.test/defpredicates clojure.core/def | ||
{:lint-as {vim.test/defpredicates clojure.core/def | ||
vim.test/defsyntaxtest clojure.core/def}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns test-basic-sexp-indent | ||
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | ||
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
consequat.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,3 @@ bar)) | |
|
||
(#_(foo bar) | ||
a) | ||
|
||
;; vim:ft=clojure: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,3 @@ | |
|
||
(#_(foo bar) | ||
a) | ||
|
||
;; vim:ft=clojure: |
3 changes: 3 additions & 0 deletions
3
clj/resources/indent-test-cases/inherit-indentation/config.edn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{:indent? false | ||
:extra-cmds ["normal! gg" | ||
"exec \"normal! /α\\<CR>s\\<C-O>Oa\\<Esc>/β\\<CR>s\\<CR>\\<CR>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>b\\<CR>c\\<CR>\\<CR>d\\<Esc>\""]} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,3 @@ | |
(six-times [y] | ||
(* (twice y) 3))] | ||
(foo #{:foo :bar :biz} :foo)) | ||
|
||
;; vim:ft=clojure: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,3 @@ | |
(six-times [y] | ||
(* (twice y) 3))] | ||
(foo #{:foo :bar :biz} :foo)) | ||
|
||
;; vim:ft=clojure: |
2 changes: 0 additions & 2 deletions
2
...dent-test-cases/test-multibyte-indent.txt → ...t-test-cases/multibyte-indentation/in.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
(let [Δt (if foo | ||
bar | ||
baz)]) | ||
|
||
;; vim:ft=clojure: |
3 changes: 3 additions & 0 deletions
3
clj/resources/indent-test-cases/multibyte-indentation/out.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(let [Δt (if foo | ||
bar | ||
baz)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,3 @@ | |
|
||
#?@(:clj [5 6 7 8] | ||
:cljs [1 2 3 4]))) | ||
|
||
;; vim:ft=clojure: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,3 @@ | |
|
||
#?@(:clj [5 6 7 8] | ||
:cljs [1 2 3 4]))) | ||
|
||
;; vim:ft=clojure: |
3 changes: 3 additions & 0 deletions
3
clj/resources/indent-test-cases/side-effects-in-indentexpr/config.edn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{:indent? false | ||
:extra-cmds ["normal! gg" | ||
"exec \"normal! /α\\<CR>:call GetClojureIndent()\\<CR>rxj:call GetClojureIndent()\\<CR>ry\""]} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(ns vim.helpers | ||
(:require [clojure.edn :as edn] | ||
[clojure.java.shell :as shell]) | ||
(:import [java.io File FileReader PushbackReader])) | ||
|
||
(defn read-edn-file [^File file] | ||
(when (.exists file) | ||
(with-open [rdr (FileReader. file)] | ||
(edn/read (PushbackReader. rdr))))) | ||
|
||
(def ^:dynamic *vim* "vim") | ||
|
||
(defn vim! | ||
"Run commands on a file in Vim." | ||
[^File file cmds & {:keys [vimrc], :or {vimrc "NONE"}}] | ||
(let [cmds (mapcat (fn [cmd] ["-c" cmd]) cmds) | ||
args (concat ["--clean" "-N" "-u" (str vimrc)] cmds ["-c" "quitall!" "--" (str file)]) | ||
ret (apply shell/sh *vim* args)] | ||
(when (pos? (:exit ret)) | ||
(throw (ex-info "Failed to run Vim command" | ||
(assoc ret :vim *vim*, :args args)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
(ns vim.indent-test | ||
(:require [clojure.test :refer [deftest]] | ||
[vim.test :refer [test-indent]])) | ||
(:require [clojure.test :refer [deftest testing is]] | ||
[clojure.string :as str] | ||
[clojure.java.io :as io] | ||
[vim.helpers :as h]) | ||
(:import [java.io File])) | ||
|
||
(deftest test-basic-sexp-indent | ||
(test-indent "works as expected with basic S-expressions" | ||
:in "test-basic-sexp-indent.txt" | ||
:out "test-basic-sexp-indent.txt")) | ||
(defn get-test-cases [^File test-case-dir] | ||
(into [] | ||
(comp | ||
(filter #(.isDirectory ^File %)) | ||
(map #(.getName ^File %))) | ||
(.listFiles test-case-dir))) | ||
|
||
(deftest test-multibyte-indent | ||
(test-indent "with multibyte characters" | ||
:in "test-multibyte-indent.txt" | ||
:out "test-multibyte-indent.txt")) | ||
(defn run-test-case [test-case-dir test-case] | ||
(testing (str "Preparation for " test-case) | ||
(let [input (io/file test-case-dir test-case "in.clj") | ||
expected (io/file test-case-dir test-case "out.clj") | ||
actual (File/createTempFile test-case ".clj") | ||
config (let [f (io/file test-case-dir test-case "config.edn")] | ||
(or (h/read-edn-file f) {})) | ||
cmds (concat (:extra-cmds config) | ||
(when (:indent? config true) ["normal! gg=G"]) | ||
["write"])] | ||
(io/make-parents actual) | ||
(io/copy input actual) | ||
(h/vim! actual cmds :vimrc (io/file "vim/test-runtime.vim")) | ||
{:test-case test-case | ||
:expected (slurp expected) | ||
:expected-file expected | ||
:actual (slurp actual) | ||
:actual-file actual}))) | ||
|
||
(deftest test-inherit-indent | ||
(test-indent "is inherited from previous element" | ||
:in "test-inherit-indent.in" | ||
:out "test-inherit-indent.out" | ||
:keys "/α\\<CR>s\\<C-O>Oa\\<Esc>/β\\<CR>s\\<CR>\\<CR>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>b\\<CR>c\\<CR>\\<CR>d\\<Esc>")) | ||
|
||
(deftest test-side-effects-in-indentexpr | ||
(test-indent "GetClojureIndent does not move cursor" | ||
:in "test-side-effects-in-indentexpr.in" | ||
:out "test-side-effects-in-indentexpr.out" | ||
:keys "/α\\<CR>:call GetClojureIndent()\\<CR>rxj:call GetClojureIndent()\\<CR>ry")) | ||
|
||
(deftest test-reader-conditional-indent | ||
(test-indent "reader conditionals are indented like maps" | ||
:in "test-reader-conditional-indent.in" | ||
:out "test-reader-conditional-indent.out")) | ||
|
||
(deftest test-dispatch-macro-indent | ||
(test-indent "dispatch macro indentation is handled correctly" | ||
:in "test-dispatch-macro-indent.in" | ||
:out "test-dispatch-macro-indent.out")) | ||
|
||
(deftest test-special-case-indent | ||
(test-indent "special case indentation is handled correctly" | ||
:in "test-special-case-indent.in" | ||
:out "test-special-case-indent.out")) | ||
;; TODO: do this parallisation more intelligently with agents. | ||
(deftest test-indent | ||
"Runs all indentation tests in parallel" | ||
(let [test-case-dir (io/file (io/resource "indent-test-cases")) | ||
test-cases (get-test-cases test-case-dir)] | ||
(doseq [{:keys [test-case expected expected-file actual actual-file]} | ||
(pmap (partial run-test-case test-case-dir) test-cases)] | ||
(testing test-case | ||
(is (= expected actual) | ||
(format "(not= \"%s\"\n \"%s\")" expected-file actual-file)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters