From 3f4a0d5370ae6c34afe180df96add3b8522f4af1 Mon Sep 17 00:00:00 2001 From: mattkae Date: Wed, 11 May 2022 09:23:58 -0400 Subject: initial commit --- .../server/test/elisp/CMakeLists.txt | 47 ++++ .../server/test/elisp/irony-cdb-json.el | 87 +++++++ .../server/test/elisp/irony-iotask.el | 249 +++++++++++++++++++++ elpa/irony-20220110.849/server/test/elisp/irony.el | 121 ++++++++++ .../server/test/elisp/test-config.el | 14 ++ 5 files changed, 518 insertions(+) create mode 100644 elpa/irony-20220110.849/server/test/elisp/CMakeLists.txt create mode 100644 elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el create mode 100644 elpa/irony-20220110.849/server/test/elisp/irony-iotask.el create mode 100644 elpa/irony-20220110.849/server/test/elisp/irony.el create mode 100644 elpa/irony-20220110.849/server/test/elisp/test-config.el (limited to 'elpa/irony-20220110.849/server/test/elisp') diff --git a/elpa/irony-20220110.849/server/test/elisp/CMakeLists.txt b/elpa/irony-20220110.849/server/test/elisp/CMakeLists.txt new file mode 100644 index 0000000..8877a89 --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/CMakeLists.txt @@ -0,0 +1,47 @@ +# 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() +# +# 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} -Q --batch + -l package + --eval "(package-initialize)" + --eval "(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) + + set_tests_properties(check-${name}-el PROPERTIES TIMEOUT 15) +endfunction() + +add_ert_test(irony.el) +add_ert_test(irony-iotask.el) +add_ert_test(irony-cdb-json.el) diff --git a/elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el b/elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el new file mode 100644 index 0000000..a810dae --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/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" )))))) diff --git a/elpa/irony-20220110.849/server/test/elisp/irony-iotask.el b/elpa/irony-20220110.849/server/test/elisp/irony-iotask.el new file mode 100644 index 0000000..7ef213b --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/irony-iotask.el @@ -0,0 +1,249 @@ +;; -*-no-byte-compile: t; -*- +(load (concat (file-name-directory (or load-file-name + buffer-file-name)) + "test-config")) + +;; load irony-iotask +;; +;; XXX: No idea why this is necessary, test-config already adds the directory to +;; the load-path so irony is found... +(unless (require 'irony-iotask nil t) + (let ((irony-iotask-dir (expand-file-name "../../.." test-dir))) + (add-to-list 'load-path irony-iotask-dir) + (require 'irony-iotask))) + +(defun irony-iotask-echo-process-exit-filter (process output) + (when (buffer-live-p (process-buffer process)) + (with-current-buffer (process-buffer process) + (goto-char (process-mark process)) + (insert output) + (set-marker (process-mark process) (point)) + (when (>= (buffer-size) (length "exit\n")) + (should (string= (buffer-string) "exit\n")) + (erase-buffer))))) + +;; Note: these tests use process communication with the standard I/O streams. +;; The subprocess used for this communication is Emacs. +;; +;; The following article provides useful information for using Elisp as a +;; scripting language, Emacs as an interpreter, it details how the standard I/O +;; streams works in Elisp scripts: +;; - http://www.lunaryorn.com/2014/08/12/emacs-script-pitfalls.html + +(defmacro irony-iotask/with-echo-process (&rest body) + "Start an Emacs process that runs the given PROCESS-SCRIPT. + +The process is setup with `irony-iotask-setup-process'. + +It's possible to schedule some iotasks in the BODY for testing. + +There is an exposed variable named `process' available for use in +BODY. + +Elisp is used as a scripting language because it should be +available on all OSes irony-iotask support." + (declare (indent 1)) + `(let ((process-connection-type nil) + (process-adaptive-read-buffering nil) + process) + (setq process + (start-process "emacs-irony-test" + "*emacs-irony-test*" + (expand-file-name invocation-name + invocation-directory) + "-Q" + "--batch" + "--eval" + (prin1-to-string + '(let ((msg)) + (while (not (equal msg "exit")) + (setq msg (read-from-minibuffer "")) + (message msg)))))) + (unwind-protect + (progn + (irony-iotask-setup-process process) + ,@body) + ;; the iotask process filter does not clean the process buffer + ;; at the end of a request, but at the begining of a new one + (with-current-buffer (process-buffer process) + (erase-buffer)) + (set-process-filter process #'irony-iotask-echo-process-exit-filter) + (process-send-string process "exit\n") + ;; wait for the process to finish normally, or kill it if it doesn't + (with-timeout (1 (kill-process process)) + (while (process-live-p process) + (sit-for 0.05))) + ;; start with a clean buffer, + ;; Emacs 24.3 seems to keep some + (kill-buffer (process-buffer process)) + (delete-process process)))) + +;; irony-iotask-result + +(ert-deftest irony-iotask-result/ready-p-value () + (let ((result (irony-iotask-result-create))) + (should-not (irony-iotask-result-valid-p result)) + (irony-iotask-result-set-value result 1) + (should (irony-iotask-result-valid-p result)))) + +(ert-deftest irony-iotask-result/ready-p-error () + (let ((result (irony-iotask-result-create))) + (should-not (irony-iotask-result-valid-p result)) + (irony-iotask-result-set-error result 'irony-iotask-error (list "blah")) + (should (irony-iotask-result-valid-p result)))) + +(ert-deftest irony-iotask-result/set-value () + (let ((result (irony-iotask-result-create))) + (irony-iotask-result-set-value result 'blah) + (should (eq (irony-iotask-result-get result) 'blah)))) + +(irony--define-error 'irony-iotask-result/test-error + "Irony I/O task sample error") + +(ert-deftest irony-iotask-result/set-error () + (let ((result (irony-iotask-result-create))) + (irony-iotask-result-set-error result 'irony-iotask-result/test-error) + (should-error (irony-iotask-result-get result) + :type 'irony-iotask-result/test-error))) + +(ert-deftest irony-iotask-result/set-error-data () + (let ((result (irony-iotask-result-create))) + (irony-iotask-result-set-error result + 'irony-iotask-result/test-error + 'foo 'bar 'baz 'qux) + (condition-case err + (irony-iotask-result-get result) + (irony-iotask-result/test-error + (should (equal (cdr err) '(foo bar baz qux))))))) + +(ert-deftest irony-iotask-result/get-empty () + (let ((result (irony-iotask-result-create))) + (should-error (irony-iotask-result-get result) + :type 'irony-iotask-result-get-error))) + +;; task + +(irony-iotask-define-task irony-iotask/task-start-t + "doc" + :start (lambda (&optional value) + (irony-iotask-set-result (or value 42)))) + +(ert-deftest irony-iotask/task-start/simple () + (let ((task (irony-iotask-package-task irony-iotask/task-start-t))) + (irony-iotask/with-echo-process + (should (equal 42 (irony-iotask-run process task)))))) + +(ert-deftest irony-iotask/task-start/with-arguments () + (let ((task (irony-iotask-package-task irony-iotask/task-start-t 43))) + (irony-iotask/with-echo-process + (should (equal 43 (irony-iotask-run process task)))))) + +(irony-iotask-define-task irony-iotask/task-update-t + "doc" + :start (lambda (&optional hello) + (irony-iotask-send-string (format "%s\n" (or hello "hello")))) + :update (lambda (&optional hello) + (setq hello (or hello "hello")) + (when (string= (buffer-string) (format "%s\n" hello)) + (irony-iotask-set-result (format "%s ok" hello))))) + +(ert-deftest irony-iotask-schedule/task-update/simple () + (let ((task (irony-iotask-package-task irony-iotask/task-update-t))) + (irony-iotask/with-echo-process + (should (string= "hello ok" (irony-iotask-run process task)))))) + +(ert-deftest irony-iotask-schedule/task-update/with-arguments () + (let ((task (irony-iotask-package-task irony-iotask/task-update-t "bonjour"))) + (irony-iotask/with-echo-process + (should (string= "bonjour ok" (irony-iotask-run process task)))))) + +(irony-iotask-define-task irony-iotask/task-invalid-msg-t + "doc" + :start (lambda () + (irony-iotask-send-string "ping\n")) + :update (lambda () + (when (string= (buffer-string) "ping\n") + (throw 'invalid-msg t)))) + +(ert-deftest irony-iotask-schedule/task-update/invalid-msg () + (let ((task (irony-iotask-package-task irony-iotask/task-invalid-msg-t))) + (irony-iotask/with-echo-process + (should-error (irony-iotask-run process task) + :type 'irony-iotask-bad-data)))) + +(ert-deftest irony-iotask-chain/simple () + (let ((task (irony-iotask-chain + (irony-iotask-package-task irony-iotask/task-update-t "hi") + (irony-iotask-package-task irony-iotask/task-update-t "hej")))) + (irony-iotask/with-echo-process + (should (equal "hej ok" (irony-iotask-run process task)))))) + +(defvar irony-iotask/task-finish-var nil) +(defvar irony-iotask/task-on-var nil) +(irony-iotask-define-task irony-iotask/task-finish-t + "doc" + :start (lambda () + (irony-iotask-put :text "how") + (irony-iotask-send-string "hello\n")) + :update (lambda () + (cond + ((string= (buffer-string) "hello\n") + (irony-iotask-put :text (concat (irony-iotask-get :text) " are")) + (irony-iotask-set-result t)) + ((>= (buffer-size) (1+ (length "hello\n"))) + (throw 'invalid-msg t)))) + :on-success (lambda () + (setq irony-iotask/task-on-var "success")) + :finish (lambda () + (setq irony-iotask/task-finish-var (concat (irony-iotask-get :text) + " you?")))) + +(ert-deftest irony-iotask-schedule/task-finish/simple () + (let ((task (irony-iotask-package-task irony-iotask/task-finish-t))) + (irony-iotask/with-echo-process + (setq irony-iotask/task-finish-var nil) + (irony-iotask-run process task) + (should (equal "how are you?" irony-iotask/task-finish-var))))) + +(ert-deftest irony-iotask-schedule/task-on-success/simple () + (let ((task (irony-iotask-package-task irony-iotask/task-finish-t))) + (irony-iotask/with-echo-process + (setq irony-iotask/task-on-var nil) + (irony-iotask-run process task) + (should (equal "success" irony-iotask/task-on-var))))) + +(irony-iotask-define-task irony-iotask/task-on-error-t + "doc" + :start (lambda () + (irony-iotask-set-error 'irony-iotask-error)) + :on-error (lambda () + (setq irony-iotask/task-on-var "error"))) + +(ert-deftest irony-iotask-schedule/task-on-error/simple () + (let ((task (irony-iotask-package-task irony-iotask/task-on-error-t))) + (irony-iotask/with-echo-process + (setq irony-iotask/task-on-var nil) + (ignore-errors + (irony-iotask-run process task)) + (should (equal "error" irony-iotask/task-on-var))))) + +(ert-deftest irony-iotask-schedule/callback/recalls-schedule () + (let ((task (irony-iotask-package-task irony-iotask/task-update-t "a"))) + (irony-iotask/with-echo-process + (lexical-let ((run-process process) + results) + (irony-iotask-schedule process task + (lambda (result) + (setq results (list result)) + (irony-iotask-schedule + run-process + (irony-iotask-package-task + irony-iotask/task-update-t "b") + (lambda (result) + (setq results (append results (list result))))))) + (should (with-local-quit + (while (< (length results) 2) + (accept-process-output process 0.05)) + t)) + (should (string= "a ok" (irony-iotask-result-get (nth 0 results)))) + (should (string= "b ok" (irony-iotask-result-get (nth 1 results)))))))) diff --git a/elpa/irony-20220110.849/server/test/elisp/irony.el b/elpa/irony-20220110.849/server/test/elisp/irony.el new file mode 100644 index 0000000..fe2378b --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/irony.el @@ -0,0 +1,121 @@ +;; -*-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/find-server-executable/does-not-exists () + (let ((irony-server-install-prefix "/does/not/exists") + (exec-path nil)) + (should-error (irony--find-server-executable) + :type 'irony-server-error))) + +(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 () + (let ((cmd-line "clang -Wall -Wextra\"")) + (should-error (irony--split-command-line cmd-line) + :type 'irony-parse-error))) + +(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))))) diff --git a/elpa/irony-20220110.849/server/test/elisp/test-config.el b/elpa/irony-20220110.849/server/test/elisp/test-config.el new file mode 100644 index 0000000..224cdd0 --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/test-config.el @@ -0,0 +1,14 @@ +;; -*-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))) + +(require 'ert) -- cgit v1.2.1