diff --git a/+PlotID/@config/config.m b/+PlotID/@config/config.m index b9b4779ef6f87e15119fefcd9d1063745711ff48..c29d213cc19d946e444f4b52953e35d54b76bbf7 100644 --- a/+PlotID/@config/config.m +++ b/+PlotID/@config/config.m @@ -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) diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 909dc03cfa54528ace7aed66a63d4afe0126c61c..85a2b3dd10af0bae2870fb9c17fca88a861cd72e 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -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']; diff --git a/+PlotID/copyUserFCN.m b/+PlotID/copyUserFCN.m index cabf4904581b5793c7a128804cdc65c5c594ccfd..eaa291db81912b4e6a22fd8a306edc81491620fe 100644 --- a/+PlotID/copyUserFCN.m +++ b/+PlotID/copyUserFCN.m @@ -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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 938d8bc80d5bdeff95757803ef2d80a778269d1e..45f0a37e1c52a6a0d2df61f7ee1fe0303df61eb7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,8 @@ #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 diff --git a/CI_files/default_test.m b/CI_files/default_test.m index ae9826f4cf8ddd3071da58b980ee7d4de3e5cc40..cee8abcc575fe4b8967c5bbc71f1dd4cede0dc7a 100644 --- a/CI_files/default_test.m +++ b/CI_files/default_test.m @@ -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') diff --git a/CI_files/example_test.m b/CI_files/example_test.m new file mode 100644 index 0000000000000000000000000000000000000000..1a07617c77001c99ba09d12bdd9f38d69d300f11 --- /dev/null +++ b/CI_files/example_test.m @@ -0,0 +1,88 @@ +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 + diff --git a/CI_files/run_example_test.sh b/CI_files/run_example_test.sh new file mode 100644 index 0000000000000000000000000000000000000000..73d0907fe69c9245e873c325b4fe6f08288695e0 --- /dev/null +++ b/CI_files/run_example_test.sh @@ -0,0 +1,15 @@ +#!/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 diff --git a/Examples/PlotID_QRcode.m b/Examples/PlotID_QRcode.m index c3308984ea3584fca2444117a097f3b900a116ef..41bc5918f9d3048c6fda3fc27fe52c30dc2b4315 100644 --- a/Examples/PlotID_QRcode.m +++ b/Examples/PlotID_QRcode.m @@ -1,10 +1,10 @@ -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]); diff --git a/Examples/PlotID_advanced.m b/Examples/PlotID_advanced.m index 310e4285b2e73d37900f1dd284531641564662e5..d6fead3f73ac1173c1a2355bc7199978282d1c2c 100644 --- a/Examples/PlotID_advanced.m +++ b/Examples/PlotID_advanced.m @@ -1,4 +1,4 @@ -clear; close all; clc; +clearEnv; %% Tag and export multiple plots % here the work flow for tagging and exporting multiple plots is shown diff --git a/Examples/PlotID_centralized.m b/Examples/PlotID_centralized.m index 921917e2ed0cafbb636fd940eccefda3da506b2f..025dbbfaf1fd5a7cb47df7748837dab16ecd216d 100644 --- a/Examples/PlotID_centralized.m +++ b/Examples/PlotID_centralized.m @@ -1,4 +1,4 @@ -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 diff --git a/Examples/PlotID_variables.m b/Examples/PlotID_variables.m index 1d34b745d36e96c417bac29ab1550be936cda4d4..28d25057d7b41aca826f545bc5e988e14e97e05a 100644 --- a/Examples/PlotID_variables.m +++ b/Examples/PlotID_variables.m @@ -1,7 +1,7 @@ -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'); diff --git a/Examples/clearEnv.m b/Examples/clearEnv.m new file mode 100644 index 0000000000000000000000000000000000000000..65c5ea2bf350ad313daa4978a7cc30329cf79ff4 --- /dev/null +++ b/Examples/clearEnv.m @@ -0,0 +1,9 @@ +function [] = clearEnv() +%CLEARENV clears Environment with exception for CI testing. + +if ~exist('ciTest', 'var') + clear; close all; clc; +end + +end + diff --git a/PlotID_example.m b/PlotID_example.m index 33deaf19ac8f385537f2d543099f6906d777eca4..feecb2914c522833ccbbb212a4df4a6bc0b322bc 100644 --- a/PlotID_example.m +++ b/PlotID_example.m @@ -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)