From 081df196f4548e635c36e1ea22740850df4c05fe Mon Sep 17 00:00:00 2001 From: vandita Date: Tue, 23 Dec 2025 12:03:09 +0530 Subject: [PATCH 1/4] Added custom tasks --- buildfile.m | 8 +++ toolbox/internal/ExampleDrivenTesterTask.m | 81 ++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 toolbox/internal/ExampleDrivenTesterTask.m diff --git a/buildfile.m b/buildfile.m index 11c6cfe..d533dd6 100644 --- a/buildfile.m +++ b/buildfile.m @@ -1,6 +1,7 @@ function plan = buildfile import matlab.buildtool.tasks.CodeIssuesTask import matlab.buildtool.tasks.TestTask +import matlab.buildtool.tasks.CleanTask % Create a plan from task functions plan = buildplan(localfunctions); @@ -8,8 +9,15 @@ % Add a task to identify code issues plan("check") = CodeIssuesTask; +plan("clean") = CleanTask; + plan("test") = TestTask('./tests'); +% Run MATLAB scripts from specified folder and generate a code coverage report +reportFormat = matlab.unittest.plugins.codecoverage.CoverageReport('coverage-report'); +covPlugin = matlab.unittest.plugins.CodeCoveragePlugin.forFolder("toolbox/sampleToolbox/code", "Producing", reportFormat); +plan("runExample") = ExampleDrivenTesterTask("toolbox/sampleToolbox/examples", CodeCoveragePlugin = covPlugin); + plan.DefaultTasks = "test"; end diff --git a/toolbox/internal/ExampleDrivenTesterTask.m b/toolbox/internal/ExampleDrivenTesterTask.m new file mode 100644 index 0000000..6bbb572 --- /dev/null +++ b/toolbox/internal/ExampleDrivenTesterTask.m @@ -0,0 +1,81 @@ +classdef ExampleDrivenTesterTask < matlab.buildtool.Task + % Buildtool task to run example scripts with optional test & coverage reports. + % Inputs: + % - Folders: string array of M-script locations + % Optional Inputs: + % - CreateTestReport (logical) + % - TestReportFormat (string) + % - ReportOutputFolder (string) + % - CodeCoveragePlugin (object) + + properties + Folders (1,:) string + CreateTestReport (1,1) logical = true + TestReportFormat (1,1) string = "HTML" + OutputPath (1,1) string = "test-report" + CodeCoveragePlugin = [] + end + + methods + function task = ExampleDrivenTesterTask(folders, options) + % Constructor + arguments + folders (1,:) string + options.CreateTestReport (1,1) logical = true + options.TestReportFormat (1,1) string = "html" + options.OutputPath(1,1) string = "test-report" + options.CodeCoveragePlugin = [] + end + + task.Description = "Run published examples"; + task.Inputs = folders; + + % Basic validation + mustBeMember(options.TestReportFormat, ["html", "pdf", "docx", "xml"]); + for f = folders + if ~isfolder(f) + error("ExampleDrivenTesterTask:FolderNotFound", ... + "Folder not found: %s", f); + end + end + + task.Folders = folders; + task.CreateTestReport = options.CreateTestReport; + task.TestReportFormat = options.TestReportFormat; + task.OutputPath= options.OutputPath; + task.CodeCoveragePlugin= options.CodeCoveragePlugin; + + if task.CreateTestReport + task.Outputs = task.OutputPath; + else + task.Outputs = string.empty; + end + end + end + + methods (TaskAction, Sealed, Hidden) + + function runExampleTests(task, ~) + if task.CreateTestReport && ~isfolder(task.OutputPath) + mkdir(task.OutputPath); + end + + if isempty(task.CodeCoveragePlugin) + obj = examplesTester( ... + task.Folders, ... + CreateTestReport = task.CreateTestReport, ... + TestReportFormat = task.TestReportFormat, ... + OutputPath = task.OutputPath); + else + % Pass CodeCoveragePlugin through when provided + obj = examplesTester( ... + task.Folders, ... + CreateTestReport = task.CreateTestReport, ... + TestReportFormat = task.TestReportFormat, ... + OutputPath = task.OutputPath, ... + CodeCoveragePlugin = task.CodeCoveragePlugin); + end + obj.executeTests; + end + end +end From 8fa3334fdd954b861cb75fb4f27975a9364e0da5 Mon Sep 17 00:00:00 2001 From: vandita Date: Tue, 23 Dec 2025 12:45:53 +0530 Subject: [PATCH 2/4] Updated README.md --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 4d0e4f9..8efba9e 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,35 @@ covPlugin = matlab.unittest.plugins.CodeCoveragePlugin.forFolder("code", "Produc obj = examplesTester(["examples", "doc"], CodeCoveragePlugin = covPlugin); obj.executeTests; ``` +## Integration with MATLAB's BuildTool +Starting with MATLAB R2025a and onwards, **ExamplesDrivenTester** ships with a ready-to-use build task called `ExampleDrivenTesterTask` that provides seamless integration with MATLAB's [buildtool](https://www.mathworks.com/help/matlab/ref/buildtool.html) framework. + +When you install the toolbox in MATLAB R2025a+, you'll automatically get this pre-configured task that you can use directly in your build files. + +### Usage Examples +Add the **ExamplesDrivenTester** task to your buildfile.m using the following patterns: + +Run MATLAB scripts from specified folders and generate a test report (default behavior): +```matlab +plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"]); +``` + +Run MATLAB scripts but do NOT generate a test report: +```matlab +plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"], CreateTestReport = false); +``` + +Run MATLAB scripts and generate a test report in PDF format: +```matlab +plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"], TestReportFormat = "pdf"); +``` +Run MATLAB scripts and generate a code coverage report for code placed in the code folder: +```matlab + +reportFormat = matlab.unittest.plugins.codecoverage.CoverageReport('coverage-report'); +covPlugin = matlab.unittest.plugins.CodeCoveragePlugin.forFolder("code", "Producing", reportFormat); +plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"], CodeCoveragePlugin = covPlugin); +``` ## License From 5735023153a349c5cf79c2237c260dade2be0188 Mon Sep 17 00:00:00 2001 From: vandita Date: Tue, 23 Dec 2025 12:47:06 +0530 Subject: [PATCH 3/4] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8efba9e..2dbd480 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ obj = examplesTester(["examples", "doc"], CodeCoveragePlugin = covPlugin); obj.executeTests; ``` ## Integration with MATLAB's BuildTool -Starting with MATLAB R2025a and onwards, **ExamplesDrivenTester** ships with a ready-to-use build task called `ExampleDrivenTesterTask` that provides seamless integration with MATLAB's [buildtool](https://www.mathworks.com/help/matlab/ref/buildtool.html) framework. +Starting with MATLAB R2025a and onwards, **ExamplesDrivenTester** ships with a ready-to-use build task called `ExampleDrivenTesterTask` that provides seamless integration with [MATLAB buildtool](https://www.mathworks.com/help/matlab/ref/buildtool.html) framework. When you install the toolbox in MATLAB R2025a+, you'll automatically get this pre-configured task that you can use directly in your build files. From 1478ac44e2f3ce5050ba944b251e54d1fccd6629 Mon Sep 17 00:00:00 2001 From: vandita Date: Tue, 23 Dec 2025 21:51:58 +0530 Subject: [PATCH 4/4] Updated README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2dbd480..493475e 100644 --- a/README.md +++ b/README.md @@ -68,28 +68,28 @@ obj = examplesTester(["examples", "doc"], CodeCoveragePlugin = covPlugin); obj.executeTests; ``` ## Integration with MATLAB's BuildTool -Starting with MATLAB R2025a and onwards, **ExamplesDrivenTester** ships with a ready-to-use build task called `ExampleDrivenTesterTask` that provides seamless integration with [MATLAB buildtool](https://www.mathworks.com/help/matlab/ref/buildtool.html) framework. +From MATLAB R2025a and onwards, users can use the `ExampleDrivenTesterTask`, a ready-to-use buildtool task shipped with ExamplesDrivenTester for automated example testing. When you install the toolbox in MATLAB R2025a+, you'll automatically get this pre-configured task that you can use directly in your build files. ### Usage Examples Add the **ExamplesDrivenTester** task to your buildfile.m using the following patterns: -Run MATLAB scripts from specified folders and generate a test report (default behavior): +1. Run MATLAB scripts from specified folders and generate a test report (default behavior): ```matlab plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"]); ``` -Run MATLAB scripts but do NOT generate a test report: +2. Run MATLAB scripts but do NOT generate a test report: ```matlab plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"], CreateTestReport = false); ``` -Run MATLAB scripts and generate a test report in PDF format: +3. Run MATLAB scripts and generate a test report in PDF format: ```matlab plan("runExample") = ExampleDrivenTesterTask(["examples", "doc"], TestReportFormat = "pdf"); ``` -Run MATLAB scripts and generate a code coverage report for code placed in the code folder: +4. Run MATLAB scripts and generate a code coverage report for code placed in the code folder: ```matlab reportFormat = matlab.unittest.plugins.codecoverage.CoverageReport('coverage-report');