aa_run_with_teardown (public)
aa_run_with_teardown -test_code test_code \ [ -teardown_code teardown_code ] [ -rollback ]
Defined in packages/acs-automated-testing/tcl/aa-test-procs.tcl
Execute code in test_code and guarantee that code in teardown_code will be executed even if error is thrown. Will catch errors in teardown_code as well and provide stack traces for both code blocks.
- Switches:
- -test_code (required)
- Tcl code that sets up the test case and executes tests
- -teardown_code (optional)
- Tcl code that tears down database data etc. that needs to execute after testing even if error is thrown.
- -rollback (optional, boolean)
- If specified, any db transactions in test_code will be rolled back.
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- webtest_example
Source code: if { $rollback_p } { set test_code [string map [list @test_code@ $test_code] { set errmsg {} db_transaction { aa_start_rollback_block @test_code@ aa_end_rollback_block error "rollback tests" } on_error { # # Execute the rollback block and trigger error. # aa_end_rollback_block set errmsg [lindex [split $::errorInfo \n] 0] } aa_execute_rollback_tests if { $errmsg ne {} && $errmsg ne "rollback tests" } { error "$errmsg \n\n $::errorInfo" } }] } # Testing set setup_error_p [catch {uplevel 1 $test_code} setup_error] set setup_error_stack $::errorInfo # Teardown set teardown_error_p 0 if { $teardown_code ne "" } { set teardown_error_p [catch {uplevel 1 $teardown_code} teardown_error] set teardown_error_stack $::errorInfo } # Provide complete error message and stack trace set error_text "" if { $setup_error_p } { append error_text "Setup failed with error $setup_error\n\n$setup_error_stack" } if { $teardown_error_p } { append error_text "\n\nTeardown failed with error $teardown_error\n\n$teardown_error_stack" } if { $error_text ne "" } { error $error_text }XQL Not present: Generic, PostgreSQL, Oracle