diff --git a/doc/cmdtest.html b/doc/cmdtest.html index db248e9..eb4cbf2 100644 --- a/doc/cmdtest.html +++ b/doc/cmdtest.html @@ -547,7 +547,7 @@ $ cmdtest . t # all CMDTEST_*.rb files in both dirs <td>Be more verbose.</td></tr> <tr><td class="option-group"> <kbd><span class="option">--fast</span></kbd></td> -<td>Run fast without ensuring that timestamps of newly created/modfied +<td>Run fast without ensuring that timestamps of newly created/modified files are unique. This could make it impossible for Cmdtest to detect all side-effects of commands.</td></tr> <tr><td class="option-group"> @@ -556,11 +556,11 @@ all side-effects of commands.</td></tr> <tr><td class="option-group"> <kbd><span class="option">--xml=<var>FILE</var></span></kbd></td> <td>Write summary on JUnit XML format. -Useful when running under a continuouos integration server that +Useful when running under a continuous integration server that understands JUnit reports.</td></tr> <tr><td class="option-group"> <kbd><span class="option">-i</span></kbd></td> -<td>Run in "incermental" mode. <strong>experimental</strong> +<td>Run in "incremental" mode. <strong>experimental</strong> Cmdtest will try to run only those test methods that are failed or have changed since last time.</td></tr> </tbody> @@ -666,6 +666,9 @@ For more details and examples see the section "Matching standard output con <dt><tt class="docutils literal"><span class="pre">assert(flag,</span> <span class="pre">msg=nil)</span></tt></dt> <dd>Assert that <tt class="docutils literal"><span class="pre">flag</span></tt> is true. This assertion is a last resort, when no other assertion fits. Should normally not be used.</dd> +<dt><tt class="docutils literal"><span class="pre">time(interval)</span></tt></dt> +<dd>Assert that executing the command took a number of seconds inside the +interval given as argument.</dd> </dl> </div> <div class="section" id="helper-functions"> diff --git a/doc/cmdtest.txt b/doc/cmdtest.txt index c56f3ff..8256bd8 100644 --- a/doc/cmdtest.txt +++ b/doc/cmdtest.txt @@ -248,7 +248,7 @@ Options Be more verbose. --fast - Run fast without ensuring that timestamps of newly created/modfied + Run fast without ensuring that timestamps of newly created/modified files are unique. This could make it impossible for Cmdtest to detect all side-effects of commands. @@ -257,11 +257,11 @@ Options --xml=FILE Write summary on JUnit XML format. - Useful when running under a continuouos integration server that + Useful when running under a continuous integration server that understands JUnit reports. -i - Run in "incermental" mode. **experimental** + Run in "incremental" mode. **experimental** Cmdtest will try to run only those test methods that are failed or have changed since last time. @@ -377,6 +377,9 @@ Assertions - misc Assert that ``flag`` is true. This assertion is a last resort, when no other assertion fits. Should normally not be used. +``time(interval)`` + Assert that executing the command took a number of seconds inside the + interval given as argument. Helper functions ++++++++++++++++ diff --git a/lib/cmdtest/testcase.rb b/lib/cmdtest/testcase.rb index 29f1763..97e0f9a 100644 --- a/lib/cmdtest/testcase.rb +++ b/lib/cmdtest/testcase.rb @@ -69,6 +69,7 @@ module Cmdtest @_in_cmd = false @_comment_str = nil @_prepend_path_dirs = [] + @_t1 = @_t2 = 0 end #------------------------------ @@ -184,6 +185,17 @@ module Cmdtest #------------------------------ + def time(time_interval) + _process_after do + diff = @_t2 - @_t1 + _assert diff >= time_interval.begin && diff <= time_interval.end do + "expected time in interval #{time_interval}" + end + end + end + + #------------------------------ + def exit_zero _process_after do @_checked_status = true @@ -490,7 +502,9 @@ module Cmdtest @_runner.notify("cmdline", @_cmdline, @_comment_str) @_comment_str = nil @_runner.prepend_path_dirs(@_prepend_path_dirs) + @_t1 = Time.now @_effects = @_work_dir.run_cmd(@_cmdline) + @_t2 = Time.now @_checked_status = false