From 0a896a7e604ce7aa9a336f95df8d0be8a411471d Mon Sep 17 00:00:00 2001 From: ehennestad Date: Wed, 11 Nov 2026 21:18:26 +0100 Subject: [PATCH 1/2] fix: make RequireIssuesResolved independent of ShowIssues codecheckToolbox threw MatBox:CodeIssues:UnresolvedIssues only when ShowIssues was also true. The throw sat inside the block that displays the issues table, and that block is skipped when ShowIssues is false, which is the default. A call with RequireIssuesResolved=true alone therefore never failed, including the example in the README. The same block held the "clear issues" for calls without an output, so with ShowIssues=false a call without a semicolon displayed the issues as ans. The display, the throw and the clear are now three separate steps. Co-Authored-By: Claude Fable 5.2 --- code/+matbox/+tasks/codecheckToolbox.m | 26 ++++---- .../tests/+matboxtools/+unittest/TasksTest.m | 65 +++++++++++++++++++ 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/code/+matbox/+tasks/codecheckToolbox.m b/code/+matbox/+tasks/codecheckToolbox.m index d7d4918..ee6b350 100644 --- a/code/+matbox/+tasks/codecheckToolbox.m +++ b/code/+matbox/+tasks/codecheckToolbox.m @@ -64,21 +64,23 @@ % R2022b and later, just display issues displayIssuesTable(issues.Issues) end + end - % Throw error if unresolved issues are present at specified severity - if options.RequireIssuesResolved - if options.SeverityThreshold == "info" && issueCount.Total > 0 - throwUnresolvedCodeIssuesException() - elseif options.SeverityThreshold == "warning" && (issueCount.Warning > 0 || issueCount.Error > 0) - throwUnresolvedCodeIssuesException() - elseif options.SeverityThreshold == "error" && issueCount.Error > 0 - throwUnresolvedCodeIssuesException() - end + % Throw error if unresolved issues are present at specified severity + if options.RequireIssuesResolved + if options.SeverityThreshold == "info" && issueCount.Total > 0 + throwUnresolvedCodeIssuesException() + elseif options.SeverityThreshold == "warning" && (issueCount.Warning > 0 || issueCount.Error > 0) + throwUnresolvedCodeIssuesException() + elseif options.SeverityThreshold == "error" && issueCount.Error > 0 + throwUnresolvedCodeIssuesException() end + end - if ~nargout - clear issues - end + % Without this, a call with no output and no semicolon displays the + % issues as ans + if ~nargout + clear issues end end diff --git a/tools/tests/+matboxtools/+unittest/TasksTest.m b/tools/tests/+matboxtools/+unittest/TasksTest.m index 8a609bc..d0f04e1 100644 --- a/tools/tests/+matboxtools/+unittest/TasksTest.m +++ b/tools/tests/+matboxtools/+unittest/TasksTest.m @@ -66,6 +66,50 @@ function testCodecheckToolboxCreatesBadgeJson(testCase) str2double(badgeInfo.message)) end + function testCodecheckToolboxThrowsOnUnresolvedIssues(testCase) + sourceFolder = createFolderWithCodeWarning(pwd); + + testCase.verifyError( ... + @() runCodecheck(pwd, sourceFolder, "RequireIssuesResolved", true), ... + "MatBox:CodeIssues:UnresolvedIssues") + end + + function testCodecheckToolboxThrowsWhenShowingIssues(testCase) + sourceFolder = createFolderWithCodeWarning(pwd); + + testCase.verifyError( ... + @() runCodecheck(pwd, sourceFolder, ... + "RequireIssuesResolved", true, "ShowIssues", true), ... + "MatBox:CodeIssues:UnresolvedIssues") + end + + function testCodecheckToolboxIgnoresIssuesBelowThreshold(testCase) + sourceFolder = createFolderWithCodeWarning(pwd); + + testCase.verifyWarningFree( ... + @() runCodecheck(pwd, sourceFolder, ... + "RequireIssuesResolved", true, "SeverityThreshold", "error")) + end + + function testCodecheckToolboxAllowsIssuesByDefault(testCase) + sourceFolder = createFolderWithCodeWarning(pwd); + + testCase.verifyWarningFree(@() runCodecheck(pwd, sourceFolder)) + end + + function testCodecheckToolboxHidesIssuesByDefault(testCase) + sourceFolder = createFolderWithCodeWarning(pwd); + codecheckOptions = {"FoldersToCheck", sourceFolder, ... + "CreateBadge", false, "SaveReport", false}; %#ok Used in evalc + + % No semicolon: an output left in ans would be displayed + displayedText = evalc("matbox.tasks.codecheckToolbox(pwd, codecheckOptions{:})"); + + testCase.verifySubstring(displayedText, "Warnings: 1") + testCase.verifyTrue(~contains(displayedText, "hasCodeWarning.m"), ... + "Expected the issues not to be displayed when ShowIssues is false.") + end + function testWriteBadgeJSONFileOmitsCountsByDefault(testCase) matbox.utility.writeBadgeJSONFile("tests", "1 passed", "green", ... "OutputFolder", pwd) @@ -211,6 +255,27 @@ function testTestedWithBadgeErrorsWhenNoReleasePassed(testCase) end end +function sourceFolder = createFolderWithCodeWarning(projectRootDirectory) +% createFolderWithCodeWarning - Create a folder with one file that has one warning +% +% The file assigns a variable that is never used, which the Code Analyzer +% reports as a single issue of severity "warning". + + sourceFolder = fullfile(projectRootDirectory, "src"); + mkdir(sourceFolder) + + code = sprintf("function hasCodeWarning()\n unusedValue = 1;\nend\n"); + matbox.utility.filewrite(fullfile(sourceFolder, "hasCodeWarning.m"), code); +end + +function runCodecheck(projectRootDirectory, sourceFolder, varargin) +% runCodecheck - Check the given folder without writing a badge or a report + + matbox.tasks.codecheckToolbox(projectRootDirectory, ... + "FoldersToCheck", sourceFolder, "CreateBadge", false, ... + "SaveReport", false, varargin{:}); +end + function setMltbxFileName(projectRootDirectory, mltbxFileName) toolboxInfoFile = fullfile(projectRootDirectory, 'tools', 'MLToolboxInfo.json'); toolboxInfo = jsondecode(fileread(toolboxInfoFile)); From 170adb2946ed5cdcb7f747d04d57784ea261cadf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:54:59 +0000 Subject: [PATCH 2/2] Update GitHub badges [skip ci] --- .github/badges/tests.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/badges/tests.svg b/.github/badges/tests.svg index 0261c9f..865d413 100644 --- a/.github/badges/tests.svg +++ b/.github/badges/tests.svg @@ -1 +1 @@ -tests: 110 passedtests110 passed +tests: 115 passedtests115 passed