Getting started

Note: At the moment, this example only works with Tcl v8.5 or earlier. See Using more than one Tcl version on one system for details.

Create a file hello.tcl with the following content:

if { $argc == 0 } {
    puts "Hello World!"
} else {
    for {set i 0} {$i<$argc} {incr i} {
        if { $i == 0 } {
            set hello "Hello [lindex $argv $i]"
        } elseif { $i == $argc - 1 } {
            set hello "$hello and [lindex $argv $i]"
        } else {
            set hello "$hello, [lindex $argv $i]"
        }
    }
    puts $hello
}

Execute hello.tcl using the tclsh interpreter:

$ coveragescannertcl tclsh hello.tcl Jim John James

Two files are generated:

  • tclsh.csmes: The instrumentation database of hello.tcl
  • tclsh.csexe: The execution report.

To import the execution report into its instrumentation database, execute:

$ cmcsexeimport -m tclsh.csmes --title="Jim John James" tclsh.csexe

After the import, it is possible to analyze the code coverage data directly with CoverageBrowser or generate a HTML report:

$ cmreport --title="Hello application" -m tclsh.csmes --html=tclsh.html

Using more than one Tcl version on one system

Coco does not yet support the use of tclsh for Tcl v8.6. If you want to use coveragescannertcl with tclsh, Tcl v8.5 or earlier is necessary.

On some UNIX®systems (like Debian Linux™), more than one Tcl version can be present at the same time. The executables are then distinguished by their names. On such a system, the tclsh executable of Tcl v8.5 may be called tclsh8.5.

We can then run CoverageScannerTcl to call tclsh8.5. However, this would change the names of the generated files to tclsh8.5.csmes and tclsh8.5.csexe. We can correct this with another command line option, --cs-output=tclsh. The first command in the example above now becomes:

$ coveragescannertcl --cs-output=tclsh tclsh8.5 hello.tcl Jim John James

Afterwards, the rest of the example can be executed as before.

Coco v7.2.0 ©2024 The Qt Company Ltd.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.