create a worksheet to determine coverage
TestCoverageWorksheet(p, paths, opts)
the name of a module or procedure, or a set or list of such names
(optional) string or list or set of strings; paths to test files
(optional) keyword options, see below
setlibname : truefalse or the symbol auto, default is auto
If set to true, Maple will insert a statement setting libname to its value in the current session. If set to false, Maple will not insert such a statement. If set to auto, Maple will behave as setlibname = true if libname has more than one component.
basedir : string or symbol, default currentdir()
Path relative to which paths is understood. The worksheet will contain a currentdir() command to go into this directory before reading the given paths, if any. If this is a string, it's understood as a literal path. If it is a symbol, it is expected that this is a symbol understood by kernelopts; e.g., mapledir.
newsheet : truefalse, default true
Whether to insert the content as a new worksheet.
insert : truefalse, default false
Whether to insert the content into the current worksheet.
returnxml : truefalse, default false
Whether to return the content as xml. Otherwise, return NULL.
useshowstat : truefalse, default false
To show the results, you can use either showstat or CodeTools:-Profiling:-Coverage:-Print. The worksheet will include both commands but one will be commented out; by default that's the showstat command. This option allows you to switch that around.
testfilemarkers : truefalse or the symbol auto, default is auto
If set to true, Maple will insert a call of the form CodeTools:-Test(1, 0, 'label' = str, 'quiet', 'boolout') before each read command. The string str indicates the file name that Maple is about to read. This makes it easier to interpret the result of the call to CodeTools:-TestFailures at the end of the worksheet: it will contain a test failure marking the start of each test file. Setting the option to false will omit these calls. If set to auto, the calls will be included if the number of test files specified is greater than one. If no test files are specified, this option is ignored.
This command creates a worksheet that can be used to examine test coverage of some code by some test files. This can then be used in the following cycle:
Run the worksheet by hitting the Execute Worksheet button (!!!).
See if all tests pass: if so, skip ahead to step 6.
Find which test fails. Because the read statements have semicolons after them, failure results will be shown in the worksheet. You should be able to search for them with Ctrl + F (Command+F, Mac), searching for failed.
Adjust the code and load it, and/or adjust the failing test(s).
Restart from step 1.
Find somewhere you want to improve test coverage. If you do not find such a place, you're done.
Add a test case that covers that code.
The worksheet will contain commands to execute the following steps:
A restart command.
If so directed by the setting of the setlibname option, set the libname variable.
The definition of a command to recursively list the members of a module.
Calls to this command to find all recursive members of the given module, and select the procedures among them.
Calls to CodeTools:-Profiling:-Profile to turn on profiling of all these procedures.
Calls to read in order to read the test files. These test files should have calls to the CodeTools:-Test command to do their tests. They should not include restart commands. If you do not specify the paths argument, Maple will insert instructions where to include the read statements.
Calls to showstat and to CodeTools:-Profiling:-Coverage:-Print. One of these will be commented out. The advantage of the latter is that you can quickly see if there are lines in the procedure that aren't covered; the advantage of the former is that you see all lines of code, so you have context and can understand the code better.
A call to print all entries of CodeTools:-TestFailures(), so that if there are any failures, you are informed of them explicitly. It's useful to have this at the bottom of the worksheet, so that you see it immediately after you have run it with the Execute Worksheet button.
It is typically more useful to use the default options newsheet=true and insert=false, but using the opposite here allows for easier demonstration of what the result looks like in this help page.
all_entries ≔ CodeTools:-RecursiveMembers⁡NewPackage,'output'='members':
procs ≔ select⁡type,all_entries,procedure
CodeTools:-Test⁡1,0,'label'=next test file: test/mpl/123456.tst,'quiet','boolout':
CodeTools:-Test⁡1,0,'label'=next test file: lib/NewPackage/tst/bar.tst,'quiet','boolout':
CodeTools:-Test⁡1,0,'label'=next test file: lib/NewPackage/tst/foo.tst,'quiet','boolout':
The CodeTools:-Profiling:-Coverage:-TestCoverageWorksheet command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
Download Help Document
What kind of issue would you like to report? (Optional)