From e2ea07de1eb02ec25bde3c43e3b99514ea8adae2 Mon Sep 17 00:00:00 2001 From: Lewin Probst <info@emirror.de> Date: Tue, 9 Jul 2019 12:18:46 +0200 Subject: [PATCH] Added test functions for automated testing. --- +tests/runTest.m | 19 +++++++++++++++++++ .gitlab-ci.yml | 6 ++++++ ci/runAll.m | 23 +++++++++++++++++++++++ ci/run_matlab_tests.sh | 11 +++++++++++ 4 files changed, 59 insertions(+) create mode 100644 +tests/runTest.m create mode 100644 .gitlab-ci.yml create mode 100644 ci/runAll.m create mode 100755 ci/run_matlab_tests.sh diff --git a/+tests/runTest.m b/+tests/runTest.m new file mode 100644 index 0000000..0fe2220 --- /dev/null +++ b/+tests/runTest.m @@ -0,0 +1,19 @@ +function [exitCode] = runTest(fcnHandle) +%RUNTEST Runs the test function that is specified in the given filename + +exitCode = 0; + +try + fcnHandle(); + disp("Test " + func2str(fcnHandle) + " successful!"); +catch err + disp("------- ERROR -------"); + disp("Test failed for " + func2str(fcnHandle)); + disp("Error message:"); + disp(err); + exitCode = 1; +end + + + +end diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..c5d59e6 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,6 @@ +before_script: + +artoa3: + script: + - "ci/run_matlab_tests.sh" + diff --git a/ci/runAll.m b/ci/runAll.m new file mode 100644 index 0000000..c488183 --- /dev/null +++ b/ci/runAll.m @@ -0,0 +1,23 @@ +% ARTOA3 automatic test script +% This script is used by gitlab's ci feature for automated testing. +% Can also be used locally. + +[currentDirectory, ~, ~] = fileparts(mfilename('fullpath')); +addpath(genpath(fullfile(currentDirectory, '..'))); + +testsToRun = { ... + @tests.rfb.load, ... + @tests.ric.save, ... + @tests.soundsource.load ... +}; + +aTestFailed = 0; + +for i = 1:length(testsToRun) + exitCode = tests.runTest(testsToRun{i}); + if exitCode == 1 + aTestFailed = exitCode; + end +end + +exit(aTestFailed); \ No newline at end of file diff --git a/ci/run_matlab_tests.sh b/ci/run_matlab_tests.sh new file mode 100755 index 0000000..95fd938 --- /dev/null +++ b/ci/run_matlab_tests.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +LOGFILE=lastTestRun.txt +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +matlab -nodesktop -nosplash -logfile "$DIR/$LOGFILE" -r "run('$DIR/runAll.m');"; +CODE=$? + +cat "$DIR/$LOGFILE" + +exit $CODE -- GitLab