From 54e05d16ad7d6949ebdfb1a2b7a61a842f9ad22d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Fri, 14 Sep 2018 22:41:37 +0200
Subject: [PATCH] Added gitlab-ci configuration file.

Also removed automatic installation of dependencies (done in gitlab-ci
pipeline instead).
---
 .gitlab-ci.yml      | 20 +++++++++++++++++
 Makefile            |  7 ++++--
 README.md           |  1 +
 success.sh          | 11 ++++++----
 tests/runalltests.m | 52 +++++++++++++++++++++++++++------------------
 5 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..7834d80
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,20 @@
+variables:
+  GIT_SUBMODULE_STRATEGY: normal
+  TERM: linux
+
+before_script:
+  - git clone https://git.dynare.org/Dynare/m-unit-tests
+
+testsuite_matlab:
+  stage: test
+  script:
+    - make check-matlab
+    - ./success.sh
+
+testsuite_octave:
+  stage: test
+  variables:
+    OPENBLAS_NUM_THREADS: 1
+  script:
+    - cp -r binaries/linux externals/x13
+    - ./success.sh
diff --git a/Makefile b/Makefile
index 7c1a49e..9ecdb0b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,10 @@ all: check-octave check-matlab
 
 check-octave:
 	@cd tests ;\
-	$(OCTAVE) --no-init-file --silent --no-history runalltests.m
+	$(OCTAVE) --no-init-file --silent --no-history --eval "addpath ../m-unit-tests/src; runalltests"
 
 check-matlab:
-	@$(MATLAB)  -nosplash -nodisplay -r "cd tests; runalltests; quit"
+	@$(MATLAB)  -nosplash -nodisplay -r "addpath m-unit-tests/src; cd tests; runalltests; quit"
+
+check-clean:
+	rm -f tests/*_test_*.m tests/*.csv tests/*.xls tests/*.xlsx tests/*.mat tests/failed tests/datafile_for_test
diff --git a/README.md b/README.md
index e69de29..12cf660 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1 @@
+[![pipeline status](https://git.dynare.org/Dynare/dates/badges/master/pipeline.svg)](https://git.dynare.org/Dynare/dates/commits/master)
diff --git a/success.sh b/success.sh
index 125cc1b..650a7d0 100755
--- a/success.sh
+++ b/success.sh
@@ -1,5 +1,8 @@
-#!/bin/sh
-if [ -f ./tests/failed ]
-then
-   exit 1
+#!/bin/bash
+if [[ -f ./tests/failed ]]; then
+    exit 1
+elif [[ -f ./tests/pass ]]; then
+    exit 0
+else
+    exit 1
 fi
diff --git a/tests/runalltests.m b/tests/runalltests.m
index aff3685..35194e2 100644
--- a/tests/runalltests.m
+++ b/tests/runalltests.m
@@ -1,25 +1,36 @@
+function runalltests()
+
+% Copyright (C) 2015-2018 Dynare Team
+%
+% This code 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.
+%
+% Dynare dseries submodule 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 Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+dates_src_root = []; % Initialize path as an array to be updated
+                     % when calling initialize_dseries_toolbox() script.
+
 opath = path();
 
 system('rm -f failed');
+system('rm -f pass');
 
-% Check that the m-unit-tests module is available.
-install_unit_test_toolbox = false;
-
+% Initialize m-unit-test submodule
 try
     initialize_unit_tests_toolbox;
 catch
-    urlwrite('https://git.dynare.org/Dynare/m-unit-tests/-/archive/master/m-unit-tests-master.zip','master.zip');
-    warning('off','MATLAB:MKDIR:DirectoryExists');
-    mkdir('../externals');
-    warning('on','MATLAB:MKDIR:DirectoryExists');
-    unzip('master.zip','../externals');
-    delete('master.zip');
-    addpath([pwd() '/../externals/m-unit-tests-master/src']);
-    initialize_unit_tests_toolbox;
-    install_unit_test_toolbox = true;
+    error('Missing dependency: m-unit-tests module is not available.')
 end
 
-% Initialize the dseries module
+% Initialize the dates submodule
 try
     initialize_dates_toolbox;
 catch
@@ -32,17 +43,16 @@ if isoctave
     more off;
 end
 
-tmp = dates_src_root;
-tmp = tmp(1:end-1); % Remove trailing slash.
-report = run_unitary_tests_in_directory(tmp);
+r = run_unitary_tests_in_directory(dates_src_root(1:end-1));
 
 delete('*.log');
 
-if install_unit_test_toolbox
-    rmdir('../externals/m-unit-tests-master','s');
+if any(~[r{:,3}])
+    system('touch failed');
+else
+    system('touch pass');
 end
+
 path(opath);
 
-if any(~[report{:,3}])
-    system('touch failed');
-end
\ No newline at end of file
+display_report(r);
\ No newline at end of file
-- 
GitLab