Skip to content
Snippets Groups Projects
Commit 034ce944 authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

Merge branch 'CI_testing_Examples' into 'development'

implement CI tests

See merge request !63
parents fb919d71 bfb8dfd5
No related branches found
No related tags found
2 merge requests!64Merge new CI Test into master,!63implement CI tests
Pipeline #655026 passed
......@@ -22,7 +22,7 @@ classdef config < handle
% wizard is started by the catch block
obj.configFileName = configFileName;
try %Validity Check
tmp = what("PlotID");
tmp = what("+PlotID");
tmp = strrep(tmp.path,'+PlotID','');
defaultConfigPath = fullfile(tmp,obj.configFileName);
if isfile(defaultConfigPath)
......
......@@ -57,7 +57,7 @@ end
% find scriptpath
if ~isfile(scriptPath)
scriptPath= which(['/',scriptPath]);
scriptPath= which(scriptPath);
if ~isfile(scriptPath)
msg = ['Script path: ',scriptPath, ' not found on matlab path', newline, ...
'- check spelling or us a path'];
......
......@@ -36,8 +36,8 @@ function [fListClean] = removePltIdFiles(fList)
PltID_classlist = packageContent.classes;
% Class Methods need to be listed in an additional function
Class_flist = cell(1,numel(packageContent.classes)); %preallocate
for i=1:numel(packageContent.classes)
Class_flist = cell(1,numel(PltID_classlist)); %preallocate
for i=1:numel(PltID_classlist)
temp = what(['PlotID',filesep,'@',PltID_classlist{i}]);
Class_flist{i} = temp.m;
end
......
#Based on STFS Workshop
stages:
- Run
Test Code:
stage: Run
- Testing
Default Test:
stage: Testing
tags:
- matlab
- bash
......@@ -18,3 +18,21 @@ Test Code:
when: always
expire_in: 1 week
Example Test:
stage: Testing
tags:
- matlab
- bash
script:
- cd ./CI_files
- chmod +x ./run_example_test.sh
- ./run_example_test.sh
- cat ./log.txt
artifacts:
paths:
- ./CI_files/log.txt
- ./CI_files/matlab_log.txt
when: always
expire_in: 1 week
......@@ -2,8 +2,6 @@ function [result] = default_test()
%default_test() This is a simple test if Plot ID works for the default settings
% Detailed explanation goes here
clear; clc; close all;
% set path
% starting path of gitlab runner is in CI_files
if contains(pwd,'CI_files')
......
function [result] = example_test()
% example This is a test if all PlotID example works run through
% prevent function to be affected by clear commands in examples
ciTest = true;
% set path
% starting path of gitlab runner is in CI_files
if contains(pwd,'CI_files')
cd .. % move one directory up
end
addpath('CI_files','Examples');
% clean up, if previous run failed
try
delete(['CI_files' filesep 'PlotID_export' filesep '*']);
delete(['CI_files' filesep '*.mat']);
delete(['CI_files' filesep '*.h5']);
rmdir(['CI_files' filesep 'PlotID_export'],'s');
end
exampleList = {'PlotID_example','PlotID_advanced',...
'PlotID_QRcode', 'PlotID_variables' };
% initialise
numberOfTests = numel(exampleList);
testResults = zeros(numberOfTests,1);
%start log
fid = fopen(fullfile('CI_files','log.txt'),'w');
txt = ['default test started ' newline];
fprintf(fid,txt);
% create Config for CI-Tests
fid1 = fopen(fullfile('CI_files','config.json'),'w');
configData.Author = 'CI-Test'; configData.ProjectID = 'CI-001';
txt = jsonencode(configData,'PrettyPrint',true);
%fprintf does not write paths correctly !!!
fwrite(fid1,txt);
fclose(fid1);
%% Testing Loop
for i=1:numberOfTests
clearvars -except i fid exampleList testResults
try
runExample(exampleList{i});
msg = ['example_test succeed example ', exampleList{i}];
catch
testResults(1) = 1; %test fails
msg = ['example_test failed at example', exampleList{i}];
warning(msg);
end
fprintf(fid,[msg, newline]);
end
%% Test result
if any(testResults)
result = 1; %fail
warning('test failed');
else
result = 0; % pass
disp('test succeed');
end
fclose(fid);
% final clean up
try
delete(['CI_files' filesep 'PlotID_export' filesep '*']);
delete(['CI_files' filesep '*.mat']);
delete(['CI_files' filesep '*.h5']);
rmdir(['CI_files' filesep 'PlotID_export'],'s');
delete(fullfile('CI_files','CI_config.json'));
end
end
function runExample(scriptName)
% runExample prevents scripts to infulence the CI script
run(scriptName);
end
#!/bin/bash
#matlab -r "disp(['Current folder: ' pwd])"
matlab $@ -nodisplay -nodesktop -nosplash -logfile matlab_log.txt -r "example_test;exit(ans);"
exitstatus=$?
if [[ $exitstatus -eq '0' ]]
then
echo "matlab succeed. Exitstatus: $exitstatus"
exit $exitstatus
else
echo "matlab failed. Exitstatus: $exitstatus"
exit $exitstatus
fi
clear; close all; clc;
clearEnv;
%% Tag the plot with a QR code (experimental)
% here the work flow for tagging the plot with a QR code is shown
% the content of the qr code is the ID
% plots and data
fig(1) = figure;
fig = figure;
[x1, y1, datapath1] = createExampleData('matlab');
plot(x1,y1,'-b'); box off; hold on; set(gca, 'TickDir', 'out', 'YLim', [0,4]);
......
clear; close all; clc;
clearEnv;
%% Tag and export multiple plots
% here the work flow for tagging and exporting multiple plots is shown
......
clear; close all; clc;
clearEnv;
%% multiple plots from the same data-set (centralized method)
% A central data folder is used for saving the research data files, the
% subfolders contain linked hdf5-files (if hdf5 is used) otherwise the data
......
clear; clc; close all;
clearEnv;
%% Example Script - How to pass Variables
% This script how to pass variables instead or additional to the DataPaths
addpath('Examples');
%% Data (only necessary for this example)
[x, y, datapath] = createExampleData('matlab');
scriptPath = mfilename('fullpath');
......
function [] = clearEnv()
%CLEARENV clears Environment with exception for CI testing.
if ~exist('ciTest', 'var')
clear; close all; clc;
end
end
......@@ -3,7 +3,7 @@
% please run Initilisation.m before first time use
%% Clear and set environment
clear; clc; close all;
clearEnv; % contains clear clc, close all
addpath('Examples');
%% Data (only necessary for this example)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment