Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ jobs:
save('test_struct.mat', 'test_struct');
startup-options: -nojvm -logfile output.log

- name: Show test results & create artifact
- name: Create artifact
uses: matlab-actions/run-command@v2
with:
command: |
addpath("${{ github.workspace }}/k-Wave");
cd("${{ github.workspace }}/k-Wave/testing/unit");
load('test_struct.mat', 'test_struct');
runUnitTests_show_results(test_struct);
runUnitTests_artifact(test_struct);
startup-options: -nojvm

Expand All @@ -48,3 +47,14 @@ jobs:
with:
name: unit_test_results
path: ${{ github.workspace }}/k-Wave/testing/unit/test_results.json

- name: Test results
uses: matlab-actions/run-command@v2
with:
command: |
addpath("${{ github.workspace }}/k-Wave");
cd("${{ github.workspace }}/k-Wave/testing/unit");
load('test_struct.mat', 'test_struct');
runUnitTests_show_results(test_struct);
startup-options: -nojvm

3 changes: 0 additions & 3 deletions k-Wave/testing/unit/runUnitTests_artifact.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ function runUnitTests_artifact(test_struct)
fclose(fid);
end

disp(' ');
disp('UNIT TEST RESULTS SAVED TO test_results.json');
disp(' ');
62 changes: 35 additions & 27 deletions k-Wave/testing/unit/runUnitTests_show_results.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ function runUnitTests_show_results(test_struct)
%RUNUNITTESTS_SHOW_RESULTS Display MATLAB unit test results in a formatted summary.
%
% DESCRIPTION:
% runUnitTests_show_results displays the results from the provided test_struct
% in a formatted summary, including test details, individual test outcomes,
% and a summary of passed and failed tests.
% runUnitTests_show_results displays the results from the provided test_struct.
%

% =========================================================================
% DISPLAY SUMMARY
% =========================================================================
Expand Down Expand Up @@ -35,6 +32,26 @@ function runUnitTests_show_results(test_struct)
disp(['TESTS COMPLETED IN: ' info.completion_time]);
disp(' ');

% display test summary
disp(' ');
num_passed = sum([results.pass]);
num_failed = numel(results) - num_passed;
disp(['✅ Number of tests passed: ' num2str(num_passed)]);
disp(['❌ Number of tests failed: ' num2str(num_failed)]);
disp(' ');

% Show failed tests using test_struct
failed_idx = find(~[results.pass]);
if ~isempty(failed_idx)
disp('FAILED TESTS:');
for i = failed_idx
fn = results(i).test;
fn = fn(1:end - 2);
disp(['❌ ' fn 'failed']);
end
disp(' ');
end

% display individual test results
disp('UNIT TEST RESULTS:');

Expand All @@ -49,33 +66,24 @@ function runUnitTests_show_results(test_struct)

% append the test result
if results(i).pass
disp([' ' fn 'passed']);
disp([' ' fn 'passed']);
else
disp([' ' fn 'failed']);
disp([' ' fn 'failed']);
end

end
disp(' ');

% display test summary
disp(' ');
disp('UNIT TEST SUMMARY:');
num_passed = sum([results.pass]);
num_failed = numel(results) - num_passed;
disp(['✅ Number of tests passed: ' num2str(num_passed)]);
disp(['❌ Number of tests failed: ' num2str(num_failed)]);
disp(' ');
disp('NOTE:');
disp('Test output details are in the "Run unit tests" section of the workflow.');
disp('You can also download a JSON summary from the "Upload Artifact" section in your CI logs or dashboard.');

% Show failed tests using test_struct
failed_idx = find(~[results.pass]);
if ~isempty(failed_idx)
disp('❌ FAILED TESTS:');
for i = failed_idx
fn = results(i).test;
fn = fn(1:end - 2);
disp(fn);
if ~isempty(results(i).test_info)
fprintf('%s\n', results(i).test_info);
disp(' ');
end
end
end
disp(' ');
% Fail if any tests failed (for CI integration)
if num_failed > 0
disp(' ');
disp('Exiting so that CI detects test failure.');
exit(1);
end
end
Loading