From ea8bfd71c120e669bcddd902f1f3943fef3eaa1f Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:30:11 +0100 Subject: [PATCH 01/16] change workflow settings for testing --- .github/workflows/unit_tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index a9e66f8..f7cdd0b 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -2,11 +2,6 @@ name: Run unit tests on: push: - branches: - - main - pull_request: - branches: - - main jobs: unit-tests: @@ -28,7 +23,7 @@ jobs: command: | addpath("${{ github.workspace }}/k-Wave"); cd("${{ github.workspace }}/k-Wave/testing/unit"); - test_struct = runUnitTests("",false); + test_struct = runUnitTests("save",false); save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log From abbfda7f48a7e98b67d91364aa26330a303ae712 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:33:44 +0100 Subject: [PATCH 02/16] remove test info for failed tests --- k-Wave/testing/unit/runUnitTests_show_results.m | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index f27ce9e..2e6e845 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -49,9 +49,9 @@ 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 @@ -73,9 +73,5 @@ function runUnitTests_show_results(test_struct) 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 \ No newline at end of file From 5d90eaedd4ed69ca707f77fbd3e88f89aa621ba1 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:46:51 +0100 Subject: [PATCH 03/16] run workflow on all tests --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index f7cdd0b..3a5aed2 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -23,7 +23,7 @@ jobs: command: | addpath("${{ github.workspace }}/k-Wave"); cd("${{ github.workspace }}/k-Wave/testing/unit"); - test_struct = runUnitTests("save",false); + test_struct = runUnitTests("",false); save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log From aff0b7e907e83235274b84d240a51ad7caf60218 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:15:33 +0100 Subject: [PATCH 04/16] refactor workflow: separate show test results and create artifact steps --- .github/workflows/unit_tests.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 3a5aed2..db63a1c 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -27,7 +27,7 @@ jobs: save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log - - name: Show test results & create artifact + - name: Show test results uses: matlab-actions/run-command@v2 with: command: | @@ -35,6 +35,15 @@ jobs: cd("${{ github.workspace }}/k-Wave/testing/unit"); load('test_struct.mat', 'test_struct'); runUnitTests_show_results(test_struct); + startup-options: -nojvm + + - 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_artifact(test_struct); startup-options: -nojvm From 7d4678caf58c1471f8a74a6da74bc38662290e3d Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:26:56 +0100 Subject: [PATCH 05/16] enhance display of results --- .../testing/unit/runUnitTests_show_results.m | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 2e6e845..42af529 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -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 % ========================================================================= @@ -35,6 +32,25 @@ 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 +end + % display individual test results disp('UNIT TEST RESULTS:'); @@ -57,21 +73,6 @@ function runUnitTests_show_results(test_struct) end % 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(' '); - -% 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); - end -end \ No newline at end of file +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.'); From cf0fc46de5119b72d556ed883cee397dad4ccd34 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:43:15 +0100 Subject: [PATCH 06/16] exit if test fails --- .github/workflows/unit_tests.yml | 19 ++++++++++--------- .../testing/unit/runUnitTests_show_results.m | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index db63a1c..716fd53 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -27,28 +27,29 @@ jobs: save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log - - name: Show test results + - 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 - - name: Create artifact + - name: Upload artifact + uses: actions/upload-artifact@v4 + 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_artifact(test_struct); + runUnitTests_show_results(test_struct); startup-options: -nojvm - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: unit_test_results - path: ${{ github.workspace }}/k-Wave/testing/unit/test_results.json diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 42af529..9e873f6 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -76,3 +76,8 @@ function runUnitTests_show_results(test_struct) 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.'); + +% Fail if any tests failed (for CI integration) +if num_failed > 0 + exit(1); +end From 9aac0c4192e038d6f8c11177c8eaf533c296f08d Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:45:28 +0100 Subject: [PATCH 07/16] run kWaveDiffusion_compare_3D_heterog tests --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 716fd53..b914b24 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -23,7 +23,7 @@ jobs: command: | addpath("${{ github.workspace }}/k-Wave"); cd("${{ github.workspace }}/k-Wave/testing/unit"); - test_struct = runUnitTests("",false); + test_struct = runUnitTests("kWaveDiffusion_compare_3D_heterog",false); save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log From d30bac8ef0e9984b16b74ffa3ddb817dd36880c0 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:48:42 +0100 Subject: [PATCH 08/16] replace exit with error for failed unit tests in CI integration --- k-Wave/testing/unit/runUnitTests_show_results.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 9e873f6..1fdf3e1 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -79,5 +79,5 @@ function runUnitTests_show_results(test_struct) % Fail if any tests failed (for CI integration) if num_failed > 0 - exit(1); + error('Some unit tests failed. See above for details.'); end From 6196596c2668307af705000306b20193d8c76196 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:49:29 +0100 Subject: [PATCH 09/16] add spacing before error message for failed unit tests in CI integration --- k-Wave/testing/unit/runUnitTests_show_results.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 1fdf3e1..0bcec88 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -71,6 +71,7 @@ function runUnitTests_show_results(test_struct) end end +disp(' '); % display test summary disp('NOTE:'); @@ -79,5 +80,6 @@ function runUnitTests_show_results(test_struct) % Fail if any tests failed (for CI integration) if num_failed > 0 + disp(' '); error('Some unit tests failed. See above for details.'); end From d46e93415efdd0be8cf58ec6590eb0fb0989ce21 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:52:00 +0100 Subject: [PATCH 10/16] remove unnecessary display messages after saving unit test results --- k-Wave/testing/unit/runUnitTests_artifact.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/k-Wave/testing/unit/runUnitTests_artifact.m b/k-Wave/testing/unit/runUnitTests_artifact.m index d62ae52..d346a3e 100644 --- a/k-Wave/testing/unit/runUnitTests_artifact.m +++ b/k-Wave/testing/unit/runUnitTests_artifact.m @@ -14,6 +14,3 @@ function runUnitTests_artifact(test_struct) fclose(fid); end -disp(' '); -disp('UNIT TEST RESULTS SAVED TO test_results.json'); -disp(' '); From 094d8900aeda9a4d064b41eb9cb927fb454d46e9 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:55:02 +0100 Subject: [PATCH 11/16] add failure messages and change exit to error for failed unit tests in CI integration --- k-Wave/testing/unit/runUnitTests_show_results.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 0bcec88..5ca52f6 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -78,8 +78,12 @@ function runUnitTests_show_results(test_struct) 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.'); +disp(' '); % Fail if any tests failed (for CI integration) if num_failed > 0 + disp('Some of the tests have failed.'); + disp('For details see the above.'); disp(' '); - error('Some unit tests failed. See above for details.'); + exit(0); +end end From 4764e9f070907ef435557ea602dea54405a728c0 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 17:00:32 +0100 Subject: [PATCH 12/16] non zero exit status --- k-Wave/testing/unit/runUnitTests_show_results.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 5ca52f6..06b78a0 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -84,6 +84,6 @@ function runUnitTests_show_results(test_struct) disp('Some of the tests have failed.'); disp('For details see the above.'); disp(' '); - exit(0); + exit(1); end end From ceed84b796868f546b216dfdbbefdd46255ea2ba Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 17:05:18 +0100 Subject: [PATCH 13/16] add message before exit to indicate CI detection of failed tests --- k-Wave/testing/unit/runUnitTests_show_results.m | 1 + 1 file changed, 1 insertion(+) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 06b78a0..91dc35d 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -84,6 +84,7 @@ function runUnitTests_show_results(test_struct) disp('Some of the tests have failed.'); disp('For details see the above.'); disp(' '); + disp('Exiting so that CI detects failed tests.'); exit(1); end end From 78621de691638e2f96ae90dbc19648990bda1892 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Tue, 29 Jul 2025 17:05:48 +0100 Subject: [PATCH 14/16] run on all tests --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index b914b24..716fd53 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -23,7 +23,7 @@ jobs: command: | addpath("${{ github.workspace }}/k-Wave"); cd("${{ github.workspace }}/k-Wave/testing/unit"); - test_struct = runUnitTests("kWaveDiffusion_compare_3D_heterog",false); + test_struct = runUnitTests("",false); save('test_struct.mat', 'test_struct'); startup-options: -nojvm -logfile output.log From 1e0aeeffa396725a498de0cbbc9c2f702c5f540b Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Wed, 30 Jul 2025 08:12:09 +0100 Subject: [PATCH 15/16] adjust formatting --- k-Wave/testing/unit/runUnitTests_show_results.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/k-Wave/testing/unit/runUnitTests_show_results.m b/k-Wave/testing/unit/runUnitTests_show_results.m index 91dc35d..2ca553e 100644 --- a/k-Wave/testing/unit/runUnitTests_show_results.m +++ b/k-Wave/testing/unit/runUnitTests_show_results.m @@ -49,6 +49,7 @@ function runUnitTests_show_results(test_struct) fn = fn(1:end - 2); disp(['❌ ' fn 'failed']); end + disp(' '); end % display individual test results @@ -81,10 +82,8 @@ function runUnitTests_show_results(test_struct) disp(' '); % Fail if any tests failed (for CI integration) if num_failed > 0 - disp('Some of the tests have failed.'); - disp('For details see the above.'); disp(' '); - disp('Exiting so that CI detects failed tests.'); + disp('Exiting so that CI detects test failure.'); exit(1); end end From 0fb5149be21de42d084814ed63d385e6e4b1e903 Mon Sep 17 00:00:00 2001 From: Stella <30465823+stellaprins@users.noreply.github.com> Date: Wed, 30 Jul 2025 08:42:28 +0100 Subject: [PATCH 16/16] correct workflow triggers --- .github/workflows/unit_tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 716fd53..0ff941c 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -2,6 +2,11 @@ name: Run unit tests on: push: + branches: + - main + pull_request: + branches: + - main jobs: unit-tests: