-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd6f40c
commit 5deea8d
Showing
14 changed files
with
234 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,6 @@ Utilities/ProjectSettings.mat | |
|
||
# Test results | ||
SoftwareTests/TestResults_* | ||
|
||
# GitLab page fodler | ||
public/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
classdef CheckTestResults < matlab.unittest.TestCase | ||
|
||
properties (SetAccess = protected) | ||
end | ||
|
||
properties (ClassSetupParameter) | ||
Project = {''}; | ||
end | ||
|
||
properties (TestParameter) | ||
Version | ||
end | ||
|
||
|
||
methods (TestParameterDefinition,Static) | ||
|
||
function Version = GetResults(Project) | ||
RootFolder = currentProject().RootFolder; | ||
Version = dir(fullfile(RootFolder,"SoftwareTests","TestResults*.txt")); | ||
Version = extractBetween([Version.name],"TestResults_",".txt"); | ||
end | ||
|
||
end | ||
|
||
methods (TestClassSetup) | ||
|
||
function SetUpSmokeTest(testCase,Project) | ||
try | ||
currentProject; | ||
catch | ||
error("Project is not loaded.") | ||
end | ||
end | ||
|
||
end | ||
|
||
methods(Test) | ||
|
||
function CheckResults(testCase,Version) | ||
File = fullfile("SoftwareTests","TestResults_"+Version+".txt"); | ||
Results = readtable(File,TextType="string"); | ||
testCase.verifyTrue(all(Results.Passed)); | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,28 @@ | ||
% Run these tests with runMyTests | ||
% All tests so far are on code expected to run without errors | ||
% If/when we end up with a version that _should_ error, | ||
% please add it to this set of examples | ||
classdef CreateBadge < matlab.unittest.TestCase | ||
|
||
properties | ||
rootProject | ||
results | ||
end | ||
|
||
|
||
methods (TestClassSetup) | ||
|
||
function setUpPath(testCase) | ||
|
||
try | ||
project = currentProject; | ||
testCase.rootProject = project.RootFolder; | ||
cd(testCase.rootProject) | ||
catch | ||
error("Load project prior to run tests") | ||
end | ||
|
||
testCase.log("Running in " + version) | ||
|
||
end % function setUpPath | ||
|
||
function readResults(testCase) | ||
Release = string([]); | ||
Passed = []; | ||
testCase.results = table(Release,Passed); | ||
|
||
ResultFiles = dir("SoftwareTests"+filesep+"TestResults_*"); | ||
for kFiles = 1:size(ResultFiles) | ||
Results = readtable(fullfile(ResultFiles(kFiles).folder,ResultFiles(kFiles).name),... | ||
Delimiter=",",TextType="string"); | ||
Release = Results.Version(1); | ||
Passed = all(Results.Status == "passed"); | ||
testCase.results(end+1,:) = table(Release,Passed); | ||
end | ||
end | ||
|
||
end % methods (TestClassSetup) | ||
|
||
methods(Test) | ||
|
||
function writeBadge(testCase) | ||
|
||
% Create JSON | ||
badgeInfo = struct; | ||
badgeInfo.schemaVersion = 1; | ||
badgeInfo.label = "tested with"; | ||
badgeInfo.message = ""; | ||
|
||
% Check that results exist: | ||
if size(testCase.results,1) == 0 | ||
badgeInfo.message = "None"; | ||
badgeInfo.color = "failed"; | ||
else | ||
for i = 1:size(testCase.results,1) | ||
if testCase.results.Passed(i) | ||
if badgeInfo.message ~= "" | ||
badgeInfo.message = badgeInfo.message + " | "; | ||
end | ||
badgeInfo.message = badgeInfo.message + string(testCase.results.Release(i)); | ||
end | ||
end | ||
badgeInfo.color = "success"; | ||
end | ||
|
||
% Write JSON file out | ||
badgeJSON = jsonencode(badgeInfo); | ||
fid = fopen(fullfile("Images","TestedWith.json"),"w"); | ||
fwrite(fid,badgeJSON); | ||
fclose(fid); | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
% Create the test suite with SmokeTest and Function test if they exist | ||
Suite = testsuite("CheckTestResults"); | ||
|
||
% Create a runner with no plugins | ||
Runner = matlab.unittest.TestRunner.withNoPlugins; | ||
|
||
% Run the test suite | ||
Results = Runner.run(Suite); | ||
|
||
% Format the results in a table and save them | ||
Results = table(Results'); | ||
Results = Results(Results.Passed,:); | ||
Version = extractBetween(string(Results.Name),"Version=",")"); | ||
|
||
|
||
% Format the JSON file | ||
Badge = struct; | ||
Badge.schemaVersion = 1; | ||
Badge.label = "Tested with"; | ||
if size(Results,1) >= 1 | ||
Badge.color = "success" | ||
Badge.message = join(Version," | "); | ||
else | ||
Badge.color = "failure"; | ||
Badge.message = "Pipeline fails"; | ||
end | ||
Badge = jsonencode(Badge); | ||
writelines(Badge,fullfile("Images","TestedWith.json")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function RunAllTest(EnableReport,ReportFolder) | ||
arguments | ||
EnableReport (1,1) logical = false; | ||
ReportFolder (1,1) string = "public"; | ||
end | ||
|
||
import matlab.unittest.plugins.TestReportPlugin; | ||
|
||
% Create a runner | ||
Runner = matlab.unittest.TestRunner.withTextOutput; | ||
if EnableReport | ||
Folder = fullfile(currentProject().RootFolder,ReportFolder); | ||
if ~isfolder(Folder) | ||
mkdir(Folder) | ||
else | ||
rmdir(Folder,'s') | ||
mkdir(Folder) | ||
end | ||
Plugin = TestReportPlugin.producingHTML(Folder,... | ||
"IncludingPassingDiagnostics",true,... | ||
"IncludingCommandWindowText",true,... | ||
"LoggingLevel",matlab.automation.Verbosity(1)); | ||
Runner.addPlugin(Plugin); | ||
end | ||
|
||
% Create the test suite with SmokeTest and Function test if they exist | ||
Suite = testsuite("SmokeTests"); | ||
Suite = [Suite testsuite("FunctionTests")]; | ||
|
||
% Run the test suite | ||
Results = Runner.run(Suite); | ||
|
||
if EnableReport | ||
web(fullfile(Folder,"index.html")) | ||
else | ||
T = table(Results); | ||
disp(newline + "Test summary:") | ||
disp(T) | ||
end | ||
|
||
% Format the results in a table and save them | ||
ResultsTable = table(Results') | ||
writetable(ResultsTable,fullfile("SoftwareTests","TestResults_"+release_version+".txt")); | ||
|
||
% Assert success of test | ||
assertSuccess(Results); | ||
|
||
end |
Oops, something went wrong.