From af20d1dcfd4e38f073098bafeaaedba5ede00268 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr>
Date: Fri, 8 Jun 2018 14:12:37 +0200
Subject: [PATCH] added a custom target to launch continuous integration tests:
 make ci

---
 ci/scripts/test.sh      | 40 +++++++++++++++++++++++++++-------------
 cmake/hysop_tests.cmake |  3 +++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/ci/scripts/test.sh b/ci/scripts/test.sh
index eceb2693f..b88262561 100755
--- a/ci/scripts/test.sh
+++ b/ci/scripts/test.sh
@@ -1,8 +1,13 @@
 #!/bin/bash
 set -e
 
-if [ $# -ne 3 ]; then
-    echo "Usage ./test install_folder hysop_folder cache_dir"
+if [ $# -lt 2 ]; then
+    echo "Usage ./test install_folder hysop_folder [cache_dir]"
+    exit 1
+fi
+
+if [ $# -gt 3 ]; then
+    echo "Usage ./test install_folder hysop_folder [cache_dir]"
     exit 1
 fi
 
@@ -18,18 +23,25 @@ fi
 
 INSTALL_DIR=$1
 HYSOP_DIR=$2
-CACHE_DIR=$3
-
-if [ -d "$CACHE_DIR" ]; then
-    echo "Cache directory '$CACHE_DIR' was found."
-    mkdir -p /root/.cache
-    cp -r $CACHE_DIR/* /root/.cache
+if [ $# -eq 3 ]; then
+    CACHE_DIR=$3
+    HAS_CACHE_DIR=true
 else
-    echo "Cache directory '$CACHE_DIR' was not found."
-    mkdir -p $CACHE_DIR
+    HAS_CACHE_DIR=false
 fi
 
-export PYTHONPATH="$INSTALL_DIR/lib/python2.7/site-packages"
+if [ "$HAS_CACHE_DIR" = true ]; then
+    if [ -d "$CACHE_DIR" ]; then
+        echo "Cache directory '$CACHE_DIR' was found."
+        mkdir -p /root/.cache
+        cp -r $CACHE_DIR/* /root/.cache
+    else
+        echo "Cache directory '$CACHE_DIR' was not found."
+        mkdir -p $CACHE_DIR
+    fi
+fi
+
+export PYTHONPATH="$INSTALL_DIR/lib/python2.7/site-packages:$PYTHONPATH"
 python -c 'import hysop; print hysop'
 
 # long backend dependent tests
@@ -49,7 +61,9 @@ python "$HYSOP_DIR/operator/tests/test_directional_advection.py"
 python "$HYSOP_DIR/operator/tests/test_directional_diffusion.py"
 python "$HYSOP_DIR/operator/tests/test_directional_stretching.py"
 
-cp -r /root/.cache/* $CACHE_DIR/
-find $CACHE_DIR -name '*.lock' -delete
+if [ "$HAS_CACHE_DIR" = true ]; then
+    cp -r /root/.cache/* $CACHE_DIR/
+    find $CACHE_DIR -name '*.lock' -delete
+fi
 
 exit 0
diff --git a/cmake/hysop_tests.cmake b/cmake/hysop_tests.cmake
index 8161e3590..8288fa8f9 100755
--- a/cmake/hysop_tests.cmake
+++ b/cmake/hysop_tests.cmake
@@ -96,3 +96,6 @@ foreach(testfile ${py_doctest_files})
   add_test("doctest_${testName}" py.test -v --doctest-modules ${exename})
 endforeach()
 
+# Add custom target to launch continuous integration tests
+add_custom_target(ci COMMAND ${CMAKE_SOURCE_DIR}/ci/scripts/test.sh ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/hysop)
+
-- 
GitLab