Permalink
Browse files

Fix CI and target test setup

  • Loading branch information...
cslux committed May 22, 2018
1 parent e346124 commit 7019960aa5657fabd7819a1e88ad30514f60b3d9
Showing with 141 additions and 80 deletions.
  1. +13 −7 .dir-locals.el
  2. +4 −6 .travis.yml
  3. +12 −10 CMakeLists.txt
  4. +3 −4 README.org
  5. +46 −26 automated_tests/test_runner.py
  6. +59 −22 scripts/travis.sh
  7. +4 −5 src/CMakeLists.txt
View
@@ -1,9 +1,15 @@
;;; Directory Local Variables
;;; See Info node `(emacs) Directory Variables' for more information.
((c++-mode . ((c-basic-offset . 4)
(indent-tabs-mode . nil))))
((cmake-mode . ((cmake-tab-width . 4)
(indent-tabs-mode . nil))))
((nil . ((indent-tabs-mode . nil))))
;;; For more information see (info "(emacs) Directory Variables")
((nil
(indent-tabs-mode))
(c++-mode
(c-basic-offset . 4)
(indent-tabs-mode))
(cmake-mode
(cmake-tab-width . 4)
(indent-tabs-mode))
(python-mode
(python-indent-offset . 4)
(tab-width . 4)
(indent-tabs-mode)))
View
@@ -11,11 +11,8 @@ addons:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- gnupg
- llvm
- build-essential
- emacs
- g++-4.9
- python3-pip
- libcppunit-dev
git:
@@ -26,13 +23,14 @@ matrix:
- os: linux
compiler: g++
dist: trusty
env: T=g++-linux COMPILER_VERSION=4.8
env: T=g++-linux COMPILER_VERSION=-4.9
- os: osx
compiler: clang
env: T=clang-osx
branches:
only:
- master
- develop
script: ./scripts/travis.sh
View
@@ -6,7 +6,7 @@ set(RTAGS_VERSION_DATABASE 125)
set(RTAGS_VERSION_SOURCES_FILE 14)
set(RTAGS_VERSION ${RTAGS_VERSION_MAJOR}.${RTAGS_VERSION_MINOR}.${RTAGS_VERSION_DATABASE})
set(RCT_WITH_TESTS ${BUILD_TESTS})
set(RCT_WITH_TESTS ${BUILD_TESTING})
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
@@ -73,24 +73,26 @@ if (RTAGS_ENABLE_DEV_OPTIONS)
set(CPACK_SOURCE_GENERATOR ${CPACK_GENERATOR})
set(CPACK_SOURCE_IGNORE_FILES
"~$"
"\\\\.gitignore$"
"\\\\.gitmodules$"
"^${PROJECT_SOURCE_DIR}/.git/"
"^${PROJECT_SOURCE_DIR}/build/"
)
"~$"
"\\\\.gitignore$"
"\\\\.gitmodules$"
"^${PROJECT_SOURCE_DIR}/.git/"
"^${PROJECT_SOURCE_DIR}/build/"
)
include(CPack)
endif ()
include(CTest)
if (BUILD_TESTS)
if (BUILD_TESTING)
add_test(SBRootTest perl "${CMAKE_SOURCE_DIR}/tests/sbroot/sbroot_test.pl" "${CMAKE_BINARY_DIR}/bin")
add_test(NAME rct_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/rct/tests/" COMMAND "${CMAKE_BINARY_DIR}/src/rct/tests/rct_tests")
find_program(NOSETEST NAMES nosetests nosetests-2.7 PATHS "$ENV{HOME}/.local/bin")
if (NOSETEST)
add_test(nosetests ${NOSETEST} -w ${CMAKE_SOURCE_DIR} -v)
# strace -ff
add_test(nosetests ${NOSETEST} -w ${CMAKE_SOURCE_DIR}/automated_tests --no-byte-compile -v --nocapture)
else()
message(WARNING "Nosetests executable not found! Excluding automated_tests from tests!")
endif ()
endif ()
View
@@ -1204,14 +1204,13 @@ other formats etc), just drop us a note.
* Unit tests
There are some unit tests available both in rtags/automated_tests
and in rtags/src/rct/tests. These can be run by cmake'ing RTags like
this:
and in rtags/src/rct/tests. To enable the tests run cmake like this.
#+begin_src sh
cmake -DBUILD_TESTS=1
cmake -DBUILD_TESTING=1
#+end_src
and run like this:
After that you can run the tests calling make with the target =test=.
#+begin_src sh
make test
#+end_src
@@ -1,15 +1,21 @@
#!/usr/bin/env python
# coding=utf-8
#
# Assuming that the bins are in build/bin, run with
# Python 2 and 3 compatible.
#
# PATH=$(pwd)/build/bin:$PATH nosetests
# Assuming that the RTags binaries are in build/bin, run with:
#
# PATH=$(pwd)/build/bin:$PATH nosetests --no-byte-compile
#
# Run nosetest with --nocapture flag to see print output
#
# into the project folder.
#
from __future__ import print_function
import os
import sys
import json
import time
import subprocess as sp
from hamcrest import assert_that, has_length, has_item
@@ -19,15 +25,19 @@
def create_compile_commands(test_dir, test_files):
"""
Create dict of compile commands
"""
return [dict(directory=os.path.abspath(test_dir), file=test_file,
command="clang++ -std=c++11 -I. -c %s" % os.path.join(test_dir, test_file))
for test_file in (src_file for src_file in test_files
if src_file.endswith('.cpp'))]
def read_locations(project_dir, lines):
def read_locations(test_dir, lines):
lines = lines.decode()
lines = [line.split(":") for line in lines.split("\n") if len(line) > 0]
return [Location(os.path.join(project_dir, line[0]), line[1], line[2]) for line in lines]
return [Location(os.path.join(test_dir, line[0]), line[1], line[2]) for line in lines]
class Location:
@@ -56,49 +66,59 @@ def run_rc(args):
return sp.check_output(args)
def wait_for(p, match):
while p.poll() is None:
l = p.stdout.readline() # This blocks until it receives a newline.
print l
if match in l:
break
def run(rdm, project_dir, test_dir, test_files, rc_command, expected_locations):
print 'running test'
def run(rdm, test_dir, test_files, rc_command, expected_locations):
"""
Run test
"""
actual_locations = \
read_locations(project_dir,
read_locations(test_dir,
run_rc([c.format(test_dir) for c in rc_command]))
# Compare that we have the same results in length and content
assert_that(actual_locations, has_length(len(expected_locations)))
print 'checking location'
for expected_location_string in expected_locations:
expected_location = Location.from_str(expected_location_string.format(test_dir))
assert_that(actual_locations, has_item(expected_location))
def setup_rdm(test_dir, test_files):
"""
Start rdm and parse the test files.
"""
rdm = sp.Popen(["rdm", "-n", socket_file, "-d", "~/.rtags_dev", "-o", "-B", "-C", "--log-flush" ],
stdout=sp.PIPE, stderr=sp.STDOUT)
wait_for(rdm, "Includepaths")
compile_commands = create_compile_commands(test_dir, test_files)
# Wait for rdm
for _ in range(10):
try:
print(run_rc(["-w"]))
break
except sp.CalledProcessError:
time.sleep(0.01)
pass
# Parse the test files
for c in compile_commands:
run_rc(["-c", c['command']])
wait_for(rdm, "Jobs took")
run_rc(["--project-root", test_dir, "-c", c['command']])
print(run_rc(["-w"]))
while True:
try:
run_rc(["--is-indexing"])
break
except sp.CalledProcessError:
time.sleep(0.01)
return rdm
def test_generator():
base_test_dir = os.path.dirname(os.path.abspath(__file__))
project_dir = os.path.abspath(os.path.join(base_test_dir, os.path.pardir))
for test_dir, _, test_files in tuple(os.walk(base_test_dir))[1:]:
print 'Test directory:',test_dir
print 'Test files:',test_files
if "ForwardDeclaration" in test_dir:
continue
if "__pycache__" in test_dir or "ForwardDeclaration" in test_dir:
continue
expectations = json.load(open(os.path.join(test_dir, "expectation.json"), 'r'))
rdm = setup_rdm(test_dir, test_files)
for e in expectations:
test_generator.__name__ = os.path.basename(test_dir)
yield run, rdm, project_dir, test_dir, test_files, e["rc-command"], e["expectation"]
yield run, rdm, test_dir, test_files, e["rc-command"], e["expectation"]
rdm.terminate()
rdm.wait()
View
@@ -25,25 +25,14 @@
# - LUA_VERSION (default value is "5.3.2")
# - LUA_DISABLE (default value is "", set it to anything to disable lua
# extension for that matrix)
declare -a CMAKE_PARAMS=("-DCMAKE_CXX_COMPILER=$CXX-$COMPILER_VERSION"
"-DRTAGS_NO_INSTALL=1"
"-DBUILD_TESTS=1"
"-DCMAKE_C_COMPILER=$CC-$COMPILER_VERSION")
declare -a CMAKE_PARAMS=("-DCMAKE_CXX_COMPILER=$CXX$COMPILER_VERSION"
"-DBUILD_TESTING=1"
"-DCMAKE_C_COMPILER=$CC$COMPILER_VERSION")
if [ "$ASAN" ]; then
CMAKE_PARAMS+=("-DASAN=address,undefined")
fi
if [ $TRAVIS_OS_NAME = osx ]; then
TRAVIS_OS_NAME=mac$TRAVIS_OS_NAME
brew install llvm cmake python yarn
else
apt-cache search llvm
apt-cache search clang
fi
pip install --user --upgrade nose
pip install --user --upgrade PyHamcrest
LUA_DISABLE=${LUA_DISABLE:-""}
if [ ! $LUA_DISABLE ]; then
CMAKE_PARAMS+=("-DLUA_ENABLED=1")
@@ -52,11 +41,59 @@ else
echo "Running build without Lua extension."
fi # end ! $LUA_DISABLE
echo "Using compilers $CXX-$COMPILER_VERSION and $CC-$COMPILER_VERSION."
mkdir build && pushd build > /dev/null
cmake "${CMAKE_PARAMS[@]}" .. || cat CMakeFiles/CMakeError.log
make VERBOSE=1 -j2
function build()
{
mkdir build && pushd build > /dev/null
cmake "${CMAKE_PARAMS[@]}" .. || cat CMakeFiles/CMakeError.log
make VERBOSE=1 -j2
}
# All arguments will be passed on to ctest
function run_tests()
{
PATH=$(pwd)/bin:$PATH
ctest --output-on-failure --verbose $@
}
function osx()
{
## Step -- Setup
brew update
brew install llvm yarn cppunit
brew upgrade python3
python3 -m pip install --upgrade pip
pip3 install --user --upgrade nose PyHamcrest
# Add nosetest bin dir to the env path var
PATH=$PATH:/Users/travis/Library/Python/3.6/bin
## Step -- Build
build
## Step -- Test
run_tests -E nose
/Users/travis/Library/Python/3.6/bin/nosetests -w /Users/travis/build/Andersbakken/rtags/automated_tests --no-byte-compile -v --nocapture
}
function gnu_linux()
{
## Step -- Setup
pip3 install --user --upgrade nose PyHamcrest
## Step -- Build
build
## Step -- Test
run_tests -E nose
rdm &
sleep 5
rc -q
/home/travis/.local/bin/nosetests -w /home/travis/build/Andersbakken/rtags/automated_tests --no-byte-compile -v --nocapture
}
if [ $TRAVIS_OS_NAME = osx ]; then
osx
else
gnu_linux
fi
PATH=$(pwd)/bin:$PATH
popd > /dev/null
make test
exit 0
View
@@ -108,9 +108,6 @@ endif ()
set(RCT_RTTI_ENABLED 1)
set(RCT_NO_INSTALL 1)
set(RCT_NO_LIBRARY 1)
if (BUILD_TEST)
set(RCT_WITH_TESTS 1)
endif ()
# Everyting which as been set either in rct/rct.cmake or rct/compiler.cmake
# doesn't need to be set in this file again.
include(rct/rct.cmake)
@@ -255,9 +252,11 @@ if (EMACS_EXECUTABLE)
ERROR_QUIET)
if (NOT EMACS_ERROR)
string(REGEX MATCH "[0-9]+(\\.[0-9]+)*" EMACS_VERSION ${EMACS_VERSION_INFORMATION})
if ("${EMACS_VERSION}" LESS "23")
message(STATUS "Installed emacs version is to old, elisp files are not going to be installed, minimum required version is >=23!")
if ("${EMACS_VERSION}" LESS "24.3")
message(WARNING "Installed emacs version is to old, elisp files are not going to be installed, minimum required version is >=24.3!")
set(RTAGS_NO_ELISP_FILES TRUE)
else()
message(STATUS "Found emacs version ${EMACS_VERSION}")
endif ()
else ()
message(STATUS "Could not get emacs version (\"emacs --version\"), elisp files are not going to be installed")

0 comments on commit 7019960

Please sign in to comment.