Changes between Version 9 and Version 10 of Tests


Ignore:
Timestamp:
Sep 8, 2013, 4:57:33 PM (11 years ago)
Author:
marius@…
Comment:

added more things; some link will work only after merge

Legend:

Unmodified
Added
Removed
Modified
  • Tests

    v9 v10  
    11=== Intro ===
    22
    3 The MacPorts testing framework uses [[http://wiki.tcl.tk/1502 | tcltest]] for its unit tests as well as regression tests.
     3The MacPorts testing framework uses [[http://wiki.tcl.tk/1502 | tcltest]] for its unit tests as well as regression tests. The framework has been developed during GSoC 13 by Marius Coțofană.
     4
     5To keep things simple, each module of MacPorts ([[https://trac.macports.org/browser/trunk/base/src/macports1.0 | macports1.0]], [[https://trac.macports.org/browser/trunk/base/src/package1.0 | package1.0]], [[https://trac.macports.org/browser/trunk/base/src/port1.0 | port1.0]], [[https://trac.macports.org/browser/trunk/base/src/registry2.0 | registry2.0]]) has it's own 'tests/' directory. Each Tcl script in a module (e.g. [[https://trac.macports.org/browser/trunk/base/src/macports1.0/macports.tcl | macports.tcl]]) has its own test script located in the 'test' directory, with the same name and the '.test' extension (e.g. [[https://trac.macports.org/browser/trunk/base/src/macports1.0/tests/macports.test | macports.test]]). Every proc in a script (e.g. [[https://trac.macports.org/browser/trunk/base/src/macports1.0/macports.tcl#L334 | proc macports::findBinary]]) should have it's own test proc (e.g. [[https://trac.macports.org/browser/trunk/base/src/macports1.0/tests/macports.test#L334 | test findBinary]]) in the corresponding test file. Test procs should maintain the order in the original script and should be independent one of another.
     6
    47Maintainer: marius [at] macports.org
    58
     
    710
    811The easiest way to run all the tests, is to use the target in the Makefile.
    9 * make test
     12{{{
     13make test
     14}}}
    1015
    11 Each 'tests/' directory has a [[https://trac.macports.org/browser/branches/gsoc13-tests/src/macports1.0/tests/test.tcl | test.tcl]] file, used by the make target to run all tests and format the output, making it easy to read.
     16Each 'tests/' directory has a [[https://trac.macports.org/browser/branches/gsoc13-tests/src/macports1.0/tests/test.tcl | test.tcl]] file, used by the make target to run all tests and format the output, making it easy to read. The script just runs the tests individually, printing the test file name, the total number of tests, number of passed, skipped, failed as well as constraints or errors of failed tests. This is one possible output when running macports.test:
     17{{{
     18Total:31 Passed:31 Failed:00 Skipped:00  macports.test
     19}}}
     20
     21Many tests need root privileges to run correctly, but will be auto skipped in the other case. Constarints are printed just bellow the final result, together with the number of test cases that require it, as so:
     22{{{
     23Total:31 Passed:24 Failed:00 Skipped:07  macports.test
     24    Constraint: 7       root
     25}}}
     26
     27The stack trace of an error that occurs during a test is printed below the constraints (if any).
     28
    1229The file can be used also to:
    13 * run all tests:                ' tclsh test.tcl '
    14 * get debug info:               ' tclsh test.tcl -debug \[0-3\] '
    15 * list individual test files:   ' tclsh test.tcl -l '
    16 * run specific test files:      ' tclsh test.tcl -t macports.test '
    17 * print help message:        ' tclsh test.tcl -h '
     30* run all tests:
     31{{{
     32tclsh test.tcl
     33}}}
     34* get debug info:
     35{{{
     36tclsh test.tcl -debug \[0-3\]
     37}}}
     38* list individual test files:
     39{{{
     40tclsh test.tcl -l
     41}}}
     42* run specific test files:
     43{{{
     44tclsh test.tcl -t macports.test
     45}}}
     46* print help message:
     47{{{
     48tclsh test.tcl -h
     49}}}
    1850
    1951Specific test cases can be run using the '-match' argument for the file that contains the test, from its parent directory.
    20 * tclsh macports.test -match mportclose
     52{{{
     53tclsh macports.test -match mportclose
     54}}}
    2155
    22 Regression tests can be found in ' trunk/base/tests/ ' and can be  run just as unit tests.
     56Regression tests can be found in [[https://trac.macports.org/browser/trunk/base/tests/test | trunk/base/tests/test]] and can be  run just as unit tests, using 'make test' from the parent directory.
    2357
    2458
    2559=== Must know ===
    2660
    27 * regression tests have their own directory, found in ' trunk/base/tests/ '
     61* the tests can be run only on an installed version of Macports ( so make sure you have run 'sudo make install' )
     62* regression tests have their own directory, found in [[https://trac.macports.org/browser/trunk/base/tests/test | trunk/base/tests/test]]
    2863* 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 ([[https://trac.macports.org/browser/branches/gsoc13-tests/src/macports1.0/tests/Portfile | Portfile]], [[https://trac.macports.org/browser/branches/gsoc13-tests/src/macports1.0/tests/test.tcl | test.tcl]])
    2964* each file in a module has a corresponding test file (.test extension) in the ‘tests/’ directory
     
    3974{{{
    4075# include required tcltest package and set namespace
    41 package require tcltest 2
     76'''package require tcltest 2'''
    4277namespace import tcltest::*
    4378
     
    4580set pwd [file normalize $argv0]
    4681set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]
     82
     83# the macports_fastload.tcl file needs to be sourced so we
     84# can directly require packages later on
     85source ../../macports1.0/macports_fastload.tcl
    4786
    4887# debug options