Changes between Version 9 and Version 10 of Tests
- Timestamp:
- Sep 8, 2013, 4:57:33 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Tests
v9 v10 1 1 === Intro === 2 2 3 The MacPorts testing framework uses [[http://wiki.tcl.tk/1502 | tcltest]] for its unit tests as well as regression tests. 3 The 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 5 To 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 4 7 Maintainer: marius [at] macports.org 5 8 … … 7 10 8 11 The easiest way to run all the tests, is to use the target in the Makefile. 9 * make test 12 {{{ 13 make test 14 }}} 10 15 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. 16 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. 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 {{{ 18 Total:31 Passed:31 Failed:00 Skipped:00 macports.test 19 }}} 20 21 Many 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 {{{ 23 Total:31 Passed:24 Failed:00 Skipped:07 macports.test 24 Constraint: 7 root 25 }}} 26 27 The stack trace of an error that occurs during a test is printed below the constraints (if any). 28 12 29 The 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 {{{ 32 tclsh test.tcl 33 }}} 34 * get debug info: 35 {{{ 36 tclsh test.tcl -debug \[0-3\] 37 }}} 38 * list individual test files: 39 {{{ 40 tclsh test.tcl -l 41 }}} 42 * run specific test files: 43 {{{ 44 tclsh test.tcl -t macports.test 45 }}} 46 * print help message: 47 {{{ 48 tclsh test.tcl -h 49 }}} 18 50 19 51 Specific 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 {{{ 53 tclsh macports.test -match mportclose 54 }}} 21 55 22 Regression tests can be found in ' trunk/base/tests/ ' and can be run just as unit tests.56 Regression 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. 23 57 24 58 25 59 === Must know === 26 60 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]] 28 63 * 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]]) 29 64 * each file in a module has a corresponding test file (.test extension) in the ‘tests/’ directory … … 39 74 {{{ 40 75 # include required tcltest package and set namespace 41 package require tcltest 2 76 '''package require tcltest 2''' 42 77 namespace import tcltest::* 43 78 … … 45 80 set pwd [file normalize $argv0] 46 81 set 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 85 source ../../macports1.0/macports_fastload.tcl 47 86 48 87 # debug options