From f5e62c16fba78083d356f846e9baaa18bfa054d8 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Sat, 23 May 2015 11:14:18 +0200 Subject: [PATCH] add unit test for a simple CXX project --- .gitignore | 10 ++++++++++ test/cxx/cmake/autocmake.cfg | 10 ++++++++++ test/cxx/cmake/custom/custom.cmake | 1 + test/cxx/example.cpp | 7 +++++++ test/test.py | 26 ++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 .gitignore create mode 100644 test/cxx/cmake/autocmake.cfg create mode 100644 test/cxx/cmake/custom/custom.cmake create mode 100644 test/cxx/example.cpp create mode 100644 test/test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..547953c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.pyc +__pycache__/ + +# generated by unit tests +test/*/CMakeLists.txt +test/*/build/ +test/*/cmake/bootstrap.py* +test/*/cmake/lib/ +test/*/cmake/modules/ +test/*/setup.py diff --git a/test/cxx/cmake/autocmake.cfg b/test/cxx/cmake/autocmake.cfg new file mode 100644 index 0000000..555eb80 --- /dev/null +++ b/test/cxx/cmake/autocmake.cfg @@ -0,0 +1,10 @@ +[project] +name: example + +[cxx] +source: https://github.com/scisoft/autocmake/raw/master/modules/UseCXX.cmake +docopt: --cxx= C++ compiler [default: g++]. +export: 'CXX=%s' % arguments['--cxx'] + +[custom] +source: custom/custom.cmake diff --git a/test/cxx/cmake/custom/custom.cmake b/test/cxx/cmake/custom/custom.cmake new file mode 100644 index 0000000..2d487d5 --- /dev/null +++ b/test/cxx/cmake/custom/custom.cmake @@ -0,0 +1 @@ +add_executable(example example.cpp) diff --git a/test/cxx/example.cpp b/test/cxx/example.cpp new file mode 100644 index 0000000..4dd9d62 --- /dev/null +++ b/test/cxx/example.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Hello World!"; + return 0; +} diff --git a/test/test.py b/test/test.py new file mode 100644 index 0000000..9f51909 --- /dev/null +++ b/test/test.py @@ -0,0 +1,26 @@ +import os +import subprocess + +HERE = os.path.abspath(os.path.dirname(__file__)) + +#------------------------------------------------------------------------------- + +def exe(command): + stdout, stderr = subprocess.Popen(command.split(), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() + return stdout, stderr + +#------------------------------------------------------------------------------- + +def test_cxx(): + os.chdir(os.path.join(HERE, 'cxx', 'cmake')) + stdout, stderr = exe('wget https://github.com/scisoft/autocmake/raw/master/bootstrap.py') + stdout, stderr = exe('python bootstrap.py --init') + stdout, stderr = exe('python bootstrap.py ..') + os.chdir(os.path.join(HERE, 'cxx')) + stdout, stderr = exe('python setup.py --cxx=g++') + os.chdir(os.path.join(HERE, 'cxx', 'build')) + stdout, stderr = exe('make') + stdout, stderr = exe('./example') + assert 'Hello World!' in stdout