—deprecated— test.fixateResultContext

—deprecated— test.fixateResultContext()

—deprecated— test.fixateResultContext(ancestorFrameIndex)

—deprecated— test.restoreResultContext()

Note: These functions predate the ability of Squish to report the full stack trace in the test log. These functions actually interfere with Squish's ability to report the full stack trace. Therefore, they are deprecated and should not be used now.

These functions temporarily enforce that test results created by other Squish functions such as Boolean test.xcompare(value1, value2) or Boolean test.verify(condition) will have their report entry rewritten such that the location of the result entry is no longer the place where text.xcompare was called but rather any of the ancestors frames of the current function.

The test.fixateResultContext function adjusts the call stack frame which is used when generating test result entries; by default, it will rewrite the location of all result entries such that they seem to stem from the parent stack frame. The same effect can be achieved by passing an optional argument 1. You can pass other values to reference other ancestor stack frames, e.g., 2 would reference the grand-parent stack framer (the caller of the caller).

Use the test.restoreResultContext to revert the effect of a previous test.fixateResultContext call. Note that the calls can be nested, i.e., multiple subsequent calls to fixateResultContext requires that restoreResultContext gets called multiple times as well.

Here are some examples; note how the test result entry triggered by the call to test.compare will be logged with a location pointing into the main function, not into the libraryFunction function:

def libraryFunction():
  test.fixateResultContext(1)
  test.compare("Apples", "Oranges")
  test.restoreResultContext()

def main():
  libraryFunction()
function libraryFunction()
{
  test.fixateResultContext(1);
  test.compare("Apples", "Oranges");
  test.restoreResultContext();
}

function main()
{
  libraryFunction();
}
sub libraryFunction
{
  test::fixateResultContext(1);
  test::compare("Apples", "Oranges");
  test::restoreResultContext();
}

sub main
{
  libraryFunction();
}
require 'squish'

include Squish

def libraryFunction
  Test.fixateResultContext(1)
  Test.compare("Apples", "Oranges")
  Test.restoreResultContext()
end

def main
  libraryFunction()
end
proc libraryFunction {} {
  test fixateResultContext 1
  test compare "Apples" "Oranges"
  test restoreResultContext
}

proc main {} {
  libraryFunction
}
  • The script file location which is associated with the comparison in case fixateResultContext/restoreResultContext is not used. This is the default - test results are associated with the location of the respective test statement.
  • The script file location which is associated with the comparison with fixateResultContext/restoreResultContext used as shown here. Due to the fixateResultContext call, the test result generated by the test.compare statement is reported at the call site, i.e., the place where libraryFunction is called.

Note: Omitting a call to test.restoreResultContext after calling test.fixateResultContext can result in very misleading test reports.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
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.

Search Results