Skip to content

Commit

Permalink
Extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed Feb 6, 2018
1 parent 029ed6c commit 8c800bd
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ install:
- sudo apt-get -y install dub

script:
- make test
- make travis
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ CASK ?= cask

all: test

test: clean-elc
travis: clean-elc
${MAKE} unit
${MAKE} compile
${MAKE} unit
${MAKE} clean-elc


test: clean-elc
${MAKE} all-tests
${MAKE} compile
${MAKE} all-tests
${MAKE} clean-elc

all-tests:
${MAKE} unit
${MAKE} file-test

unit:
${CASK} exec ert-runner
${CASK} exec ert-runner test/cmake-ide-test.el test/utils-test.el

file-test:
${CASK} exec ert-runner test/cmake-ide-test.el test/file-test.el

compile:
${CASK} exec ${EMACS} -Q -batch -f batch-byte-compile cmake-ide.el
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sandbox
3 changes: 0 additions & 3 deletions test/cmake-ide-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,5 @@ company-c-headers to break."
(cmake-ide--message "dir 1 %s" dir1))
)

(ert-deftest test-unquote ()
(should (equal (cmake-ide--unquote "\"foo\"") "foo")))

(provide 'cmake-ide-test)
;;; cmake-ide-test.el ends here
80 changes: 80 additions & 0 deletions test/file-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
;;; file-test.el --- Unit tests for cmake-ide.

;; Copyright (C) 2014-2018

;; Author: <atila.neves@gmail.com>
;; Keywords:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'f)

(defvar cmake-ide--test-path)
(defvar cmake-ide--root-path)
(setq cmake-ide--test-path (f-dirname load-file-name))
(setq cmake-ide--root-path (f-parent cmake-ide--test-path))
(add-to-list 'load-path cmake-ide--root-path)

(require 'ert)
(require 'cmake-ide)
(require 'cl-lib)

(defvar cmake-ide--sandbox-path (expand-file-name "sandbox" cmake-ide--test-path))

(defmacro with-sandbox (&rest body)
"Evaluate BODY in an empty temporary directory."
`(let* ((root-sandbox-path (expand-file-name "sandbox" cmake-ide--test-path))
(default-directory root-sandbox-path))
(when (f-dir? root-sandbox-path)
(f-delete root-sandbox-path :force))
(f-mkdir root-sandbox-path)
,@body))

(defun write-file-str (name str)
"Write to a file named NAME with contents STR."
(let ((path (expand-file-name name cmake-ide--sandbox-path)))
(f-write-text str 'utf-8 path)))


(defun equal-lists (lst1 lst2)
"If LST1 is the same as LST2 regardless or ordering."
(and (equal (length lst1) (length lst2))
(null (cl-set-difference lst1 lst2 :test 'equal))))

(ert-deftest test-one-cpp-file ()
(with-sandbox
(write-file-str "foo.cpp" "int add(int i, int j) { return i + j; }")
(write-file-str "CMakeLists.txt"
"
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
set(CMAKE_CXX_FLAGS \"-g -debug\")
add_executable(foo \"foo.cpp\")")
(cmake-ide--message "Running cmake !!!!!!1oneoneoneoene")
(cmake-ide-maybe-run-cmake)
(should (equal-lists ac-clang-flags '("-Iinc1" "-Iinc2" "-Dfoo=bar" "-S" "-F")))
(should (equal-lists company-clang-arguments ac-clang-flags))
(should (equal-lists flycheck-clang-include-path '("/tmp/inc1" "/tmp/inc2")))
(should (equal-lists flycheck-clang-definitions '("foo=bar")))
(should (equal-lists flycheck-clang-includes nil))
(should (equal-lists flycheck-clang-args '("-S" "-F" "-g")))))


(provide 'file-test)
;;; file-test.el ends here
4 changes: 4 additions & 0 deletions test/utils-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
(should (equal (cmake-ide--string-empty-p "") t))
(should (equal (cmake-ide--string-empty-p "foo") nil)))

(ert-deftest test-unquote ()
(should (equal (cmake-ide--unquote "\"foo\"") "foo")))


(provide 'utils-test)
;;; utils-test.el ends here

0 comments on commit 8c800bd

Please sign in to comment.