[MacPorts] Tests added

MacPorts noreply at macports.org
Mon Aug 26 13:06:20 PDT 2013


Page "Tests" was added by marius at macports.org
Comment: initial commit
Content:
-------8<------8<------8<------8<------8<------8<------8<------8<--------
TODO:
* run all tests method
* makefile test target
* additional files (Portfile, sources.conf)
* regression tests

=== Intro ===

The MacPorts testing framework uses tcltest [0] for its unit tests as well as regression tests.
Maintainer: marius at macports.org


=== Must know ===

* each module of MacPorts (port1.0, macports1.0, package1.0) has its own ‘tests/’ directory where the test files are located and also additional files needed (Portfile, test.tcl)
* each file in a module has a corresponding test file (.test extension) in the ‘tests/’ directory
* each proc in a file has a corresponding test case (test proc_name) in the
* each test case must be independent from each other, so they can be run individually if needed
* each test must clan all auxiliary files or directories it creates and revert all port it installs


=== Sample file ===

{{{
# include required tcltest package and set namespace
package require tcltest 2
namespace import tcltest::*

# get absolute path to current ‘tests/’ directory
set pwd [file normalize $argv0]
set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]

# debug options
# ports_debug and ports_verbose are commented out as default
# need to be set before ‘mportinit’
array set ui_options {}
#set ui_options(ports_debug)   yes
#set ui_options(ports_verbose) yes
mportinit ui_options

# source/require tested/needed files
source ../../port1.0/portutil.tcl

# additional procs needed for testing
proc registry_exists {name version {revision 0} {variants ""}} {
        global macports::registry.format
        return [${macports::registry.format}::entry_exists $name $version $revision $variants]
}


# test case example
# the test name must reflect the tested proc (remove namespaces if any)
# the test description should list specific values from the tested proc on which it depends
# or the partial cases it tests
test mportclose {
    Mport close unit test.
# the setup branch is optional
} -setup {
    set mport [mportopen file://.]
# please make output as useful as possible (even error cases)
# all sub-test cases should be part of the body branch
} -body {
    if {[catch {mportclose $mport}] != 0} {
        return "FAIL: cannot run mportclose"
    }
    return "Mport close successful."
# the cleanup branch is optional
} -cleanup {
    file delete -force $pwd/work
} -result "Mport close successful."


# print test results
cleanupTests
}}}


=== Resources ===

[0] - [[ http://wiki.tcl.tk/1502 | Tcltest official wiki page ]]
[1] - [[ http://web.archive.org/web/20080617153002/www.tclscripting.com/articles/apr06/article1.html | [2] - Getting started with tcltest ]]
[[ http://www.tcl.tk/man/tcl8.5/TclCmd/tcltest.htm | Official tcltest documentation ]]

-------8<------8<------8<------8<------8<------8<------8<------8<--------

--
Page URL: <https://trac.macports.org/wiki/Tests>
MacPorts <http://www.macports.org/>
Ports system for OS X

This is an automated message. Someone added your email address to be
notified of changes on 'Tests' page.
If it was not you, please report to .


More information about the macports-changes mailing list