Initial commit.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# On MS-Windows, emacs_dir is a special environment variable, which
|
||||
# indicates the full path of the directory in which Emacs is
|
||||
# installed.
|
||||
#
|
||||
# There is no standard location that I know of for Emacs on Windows so
|
||||
# using this special environment variable will at least help people
|
||||
# who build the server from inside Emacs.
|
||||
if(DEFINED ENV{emacs_dir})
|
||||
list(APPEND EMACS_EXECUTABLE_HINTS $ENV{emacs_dir}/bin)
|
||||
endif()
|
||||
|
||||
find_program(EMACS_EXECUTABLE emacs
|
||||
HINTS ${EMACS_EXECUTABLE_HINTS})
|
||||
|
||||
if (EMACS_EXECUTABLE)
|
||||
message(STATUS "Found emacs: ${EMACS_EXECUTABLE}")
|
||||
else()
|
||||
message(WARNING "emacs not found: elisp tests will be skipped!")
|
||||
return()
|
||||
endif()
|
||||
|
||||
#
|
||||
# add_ert_test(<FileName>)
|
||||
#
|
||||
# Create a test which run the given Elisp script using the Emacs ERT testing
|
||||
# framework.
|
||||
#
|
||||
# The target is deduced from the ``FileName`` argument, e.g: the file foo.el
|
||||
# will be the target 'check-foo-el'.
|
||||
#
|
||||
# FIXME: assumes MELPA is configured...
|
||||
function(add_ert_test test_file)
|
||||
get_filename_component(name ${test_file} NAME_WE)
|
||||
add_test(check-${name}-el
|
||||
${EMACS_EXECUTABLE} -batch
|
||||
-l package
|
||||
--eval "(package-initialize) (unless (require 'cl-lib nil t) (package-refresh-contents) (package-install 'cl-lib))"
|
||||
-l ${CMAKE_CURRENT_SOURCE_DIR}/${test_file}
|
||||
-f ert-run-tests-batch-and-exit)
|
||||
endfunction()
|
||||
|
||||
add_ert_test(irony.el)
|
||||
add_ert_test(irony-cdb-json.el)
|
@@ -0,0 +1,87 @@
|
||||
;; -*-no-byte-compile: t; -*-
|
||||
(load
|
||||
(concat (file-name-directory (or load-file-name buffer-file-name))
|
||||
"test-config"))
|
||||
|
||||
(require 'irony-cdb-json)
|
||||
(require 'cl-lib)
|
||||
|
||||
(defconst irony-cdb/compile-command
|
||||
'((file . "../src/file.cc")
|
||||
(directory . "/home/user/project/build")
|
||||
(command . "/usr/bin/clang++ -DSOMEDEF=1 -c -o file.o /home/user/project/src/file.cc")))
|
||||
|
||||
(ert-deftest cdb/parse/simple/path-is-absolute ()
|
||||
(should
|
||||
(equal "/home/user/project/src/file.cc"
|
||||
(nth 0 (irony-cdb-json--transform-compile-command
|
||||
irony-cdb/compile-command)))))
|
||||
|
||||
(ert-deftest cdb/parse/simple/compile-options ()
|
||||
(should
|
||||
(equal '("-DSOMEDEF=1")
|
||||
(nth 1 (irony-cdb-json--transform-compile-command
|
||||
irony-cdb/compile-command)))))
|
||||
|
||||
(ert-deftest cdb/parse/simple/invocation-directory ()
|
||||
(should
|
||||
(equal "/home/user/project/build"
|
||||
(nth 2 (irony-cdb-json--transform-compile-command
|
||||
irony-cdb/compile-command)))))
|
||||
|
||||
(ert-deftest cdb/choose-closest-path/chooses-closest ()
|
||||
(should
|
||||
(equal "/tmp/a/cdb"
|
||||
(irony-cdb--choose-closest-path "/tmp/a/1"
|
||||
'("/tmp/a/cdb" "/tmp/cdb")))))
|
||||
|
||||
(ert-deftest cdb/choose-closest-path/chooses-closest2 ()
|
||||
(should
|
||||
(equal "/tmp/a/cdb"
|
||||
(irony-cdb--choose-closest-path "/tmp/a/1"
|
||||
'("/tmp/cdb" "/tmp/a/cdb")))))
|
||||
|
||||
(ert-deftest cdb/choose-closest-path/prefers-deeper ()
|
||||
(should
|
||||
(equal "/tmp/a/build/cdb"
|
||||
(irony-cdb--choose-closest-path "/tmp/a/1"
|
||||
'("/tmp/a/build/cdb" "/tmp/cdb")))))
|
||||
|
||||
(ert-deftest cdb/choose-closest-path/prefers-deeper2 ()
|
||||
(should
|
||||
(equal "/tmp/a/build/cdb"
|
||||
(irony-cdb--choose-closest-path "/tmp/a/1"
|
||||
'("/tmp/cdb" "/tmp/a/build/cdb")))))
|
||||
|
||||
(ert-deftest cdb/choose-closest-path/will-survive-garbage ()
|
||||
(should
|
||||
(equal nil
|
||||
(irony-cdb--choose-closest-path "/tmp/a/1"
|
||||
'ordures))))
|
||||
|
||||
; http://endlessparentheses.com/understanding-letf-and-how-it-replaces-flet.html
|
||||
(ert-deftest cdb/locate-db/choose-among-candidates ()
|
||||
(should
|
||||
(equal "/foo/build/cdb"
|
||||
(cl-letf (((symbol-function 'locate-dominating-file)
|
||||
(lambda (file name)
|
||||
(cond
|
||||
((string= name "./cdb") "/") ; found /cdb
|
||||
((string= name "build/cdb") "/foo/") ; found /foo/build/cdb
|
||||
))))
|
||||
(irony-cdb--locate-dominating-file-with-dirs "/foo/bar/qux.cpp"
|
||||
"cdb"
|
||||
'("." "build" "out/x86_64"))))))
|
||||
|
||||
(ert-deftest cdb/locate-dominating-file-with-dirs/children-first ()
|
||||
(should
|
||||
(equal "/tmp/foo/bar/out/x86_64/cdb"
|
||||
(cl-letf (((symbol-function 'locate-dominating-file)
|
||||
(lambda (file name)
|
||||
(cond
|
||||
((string= name "./cdb") "/tmp/foo/") ; found /tmp/foo/cdb
|
||||
((string= name "out/x86_64/cdb") "/tmp/foo/bar/") ;found /tmp/foo/bar/out/x86_64/cdb
|
||||
))))
|
||||
(irony-cdb--locate-dominating-file-with-dirs "/tmp/foo/bar/qux.cpp"
|
||||
"cdb"
|
||||
'("." "out/x86_64" ))))))
|
117
.emacs.d/elpa/irony-20160203.1207/server/test/elisp/irony.el
Normal file
117
.emacs.d/elpa/irony-20160203.1207/server/test/elisp/irony.el
Normal file
@@ -0,0 +1,117 @@
|
||||
;; -*-no-byte-compile: t; -*-
|
||||
(load (concat (file-name-directory (or load-file-name
|
||||
buffer-file-name))
|
||||
"test-config"))
|
||||
|
||||
(ert-deftest irony/buffer-size-in-bytes ()
|
||||
(with-temp-buffer
|
||||
;; this smiley takes 3 bytes apparently
|
||||
(insert "☺")
|
||||
(should (equal 3 (irony--buffer-size-in-bytes)))
|
||||
(erase-buffer)
|
||||
(insert "☺\n")
|
||||
(should (equal 4 (irony--buffer-size-in-bytes)))
|
||||
(erase-buffer)
|
||||
(insert "\t")
|
||||
(should (equal 1 (irony--buffer-size-in-bytes)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/just-spaces ()
|
||||
(let ((cmd-line "clang -Wall -Wextra"))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/start-with-space ()
|
||||
(let ((cmd-line " clang -Wall -Wextra"))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/end-with-space ()
|
||||
(let ((cmd-line "clang -Wall -Wextra "))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/space-everywhere ()
|
||||
(let ((cmd-line " \t clang \t -Wall \t -Wextra\t"))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/with-quotes ()
|
||||
(let ((cmd-line "clang -Wall -Wextra \"-I/tmp/dir with spaces\""))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra" "-I/tmp/dir with spaces")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/with-quotes ()
|
||||
"Test if files are removed from the arguments list.
|
||||
|
||||
https://github.com/Sarcasm/irony-mode/issues/101"
|
||||
(let ((cmd-line "g++ -DFOO=\\\"\\\""))
|
||||
(should (equal
|
||||
'("g++" "-DFOO=\"\"")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/start-with-quotes ()
|
||||
(let ((cmd-line "\"cl ang\" -Wall -Wextra \"-I/tmp/dir with spaces\""))
|
||||
(should (equal
|
||||
'("cl ang" "-Wall" "-Wextra" "-I/tmp/dir with spaces")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/quotes-in-word ()
|
||||
(let ((cmd-line "clang -Wall -Wextra -I\"/tmp/dir with spaces\""))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra" "-I/tmp/dir with spaces")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/ill-end-quote ()
|
||||
:expected-result :failed
|
||||
(let ((cmd-line "clang -Wall -Wextra\""))
|
||||
(should (equal
|
||||
'("clang" "-Wall" "-Wextra" "-I/tmp/dir with spaces")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/backslash-1 ()
|
||||
(let ((cmd-line "clang\\ -Wall"))
|
||||
(should (equal
|
||||
'("clang -Wall")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/split-command-line/backslash-2 ()
|
||||
(let ((cmd-line "\\\\\\ clang\\ -Wall\\"))
|
||||
(should (equal
|
||||
'("\\ clang -Wall\\")
|
||||
(irony--split-command-line cmd-line)))))
|
||||
|
||||
(ert-deftest irony/extract-working-directory-option/not-specified ()
|
||||
(let ((compile-flags '("-Wall")))
|
||||
(should
|
||||
(not (irony--extract-working-directory-option compile-flags)))))
|
||||
|
||||
(ert-deftest irony/extract-working-directory-option/specified-1 ()
|
||||
(let ((compile-flags '("-working-directory" "/tmp/lol")))
|
||||
(should (equal "/tmp/lol"
|
||||
(irony--extract-working-directory-option compile-flags)))))
|
||||
|
||||
(ert-deftest irony/extract-working-directory-option/specified-2 ()
|
||||
(let ((compile-flags '("-Wall" "-working-directory=/tmp/lol" "-Wshadow")))
|
||||
(should (equal "/tmp/lol"
|
||||
(irony--extract-working-directory-option compile-flags)))))
|
||||
|
||||
;; TODO: restore functionality
|
||||
;; (ert-deftest irony/include-directories-1 ()
|
||||
;; (let ((irony-compile-flags '("-Iinclude" "-I/tmp/foo"))
|
||||
;; (irony-compile-flags-work-dir "/tmp/blah/"))
|
||||
;; (should (equal
|
||||
;; '("/tmp/blah/include" "/tmp/foo")
|
||||
;; (irony-user-search-paths)))))
|
||||
|
||||
;; (ert-deftest irony/include-directories-2 ()
|
||||
;; (let ((irony-compile-flags '("-Wextra" "-Iinclude" "-I" "foo" "-Wall"))
|
||||
;; (irony-compile-flags-work-dir "/tmp/blah/"))
|
||||
;; (should (equal
|
||||
;; '("/tmp/blah/include"
|
||||
;; "/tmp/blah/foo")
|
||||
;; (irony-user-search-paths)))))
|
2544
.emacs.d/elpa/irony-20160203.1207/server/test/elisp/support/ert.el
Normal file
2544
.emacs.d/elpa/irony-20160203.1207/server/test/elisp/support/ert.el
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
;; -*-no-byte-compile: t; -*-
|
||||
(defvar test-dir (if load-file-name
|
||||
(file-name-as-directory
|
||||
(expand-file-name (concat (file-name-directory
|
||||
load-file-name)))))
|
||||
"Elisp test directory path.")
|
||||
|
||||
;; load irony
|
||||
(unless (require 'irony nil t)
|
||||
(let ((irony-dir (expand-file-name "../../.." test-dir)))
|
||||
(add-to-list 'load-path irony-dir)
|
||||
(require 'irony)))
|
||||
|
||||
;; load ERT, fallback to a bundled version if not found in `load-path'
|
||||
(unless (require 'ert nil t)
|
||||
(let ((load-path (cons (expand-file-name "support" test-dir)
|
||||
load-path)))
|
||||
(require 'ert)))
|
Reference in New Issue
Block a user