Difference between revisions of "Patch TUT"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Our unit test framework did not have any method for skipping tests. Sometimes known failure cases are found which require temporarily skipping tests. This patch adds that functionality.
== Using Linden Lab's modified version ==


= TUT-2006-11-04 =
Linden Lab's modified version can be downloaded with
'''WARNING''': This is a patch to a pretty old version of tut, but currently the version in use.


<pre>
scripts/install.py tut
--- tut-orig/tut.h 2007-05-23 16:37:00.000000000 -0700
+++ tut-new/tut.h 2007-05-23 16:40:18.000000000 -0700
@@ -79,6 +79,15 @@
  };


  /**
which uses <code>install.xml</code> in the source tree for the right version/download-url.
+  * Exception to be throwed when skip_fail() is called.
+  */
+  class skip_failure : public std::logic_error
+  {
+    public:
+      skip_failure(const std::string& msg) : std::logic_error(msg){};
+  };
+
/**
    * Exception to be throwed when test desctructor throwed an exception.
    */
  class warning : public std::logic_error
@@ -120,8 +129,20 @@
      * ex - test throwed an exceptions
      * warn - test finished successfully, but test destructor throwed
      * term - test forced test application to terminate abnormally
+    * skip - test skipped
+    * skip_fail - test skpped because it is a known failure case
      */
-    typedef enum { ok, fail, ex, warn, term, ex_ctor } result_type;
+    typedef enum
+ {
+ ok,
+ fail,
+ ex,
+ warn,
+ term,
+ ex_ctor,
+ skip,
+ skip_fail,
+ } result_type;
    result_type result;


    /**
== Using the original source ==
@@ -168,7 +189,7 @@


    // execute tests iteratively
The original source can be downloaded from http://downloads.sourceforge.net/sourceforge/tut-framework/tut-2008-11-30.tar.gz
    virtual void rewind() = 0;
-   virtual test_result run_next() = 0;
+    virtual test_result run_next(int skip_test_id = 0) = 0;


    // execute one test
Our unit test framework did not have any method for skipping tests. Sometimes known failure cases are found which require temporarily skipping tests. The following patch adds that functionality.
    virtual test_result run_test(int n) = 0;
@@ -316,7 +337,7 @@
    /**
      * Runs all tests in specified group.
      */
-    void run_tests(const std::string& group_name) const
+    void run_tests(const std::string& group_name, int skip_test_id = 0) const
    {
      callback_->run_started();


@@ -328,7 +349,7 @@
Patch against tut-2008-11-30.tar.gz .  Save this patch as <code>tut.patch</code> in the <code>tut-2008-11-30</code> directory and apply it from a terminal program like xterm or cygwin with the command:


      try
  $ patch -p1 < tut.patch
      {
-       run_all_tests_in_group_(i);
+        run_all_tests_in_group_(i, skip_test_id);
      }
      catch( const no_more_tests& )
      {
@@ -371,12 +392,13 @@
    }
 
    private:
-    void run_all_tests_in_group_(const_iterator i) const
+    void run_all_tests_in_group_(const_iterator i, int skip_test_id = 0) const
    {
      i->second->rewind();
      for( ;; )
      {
-        test_result tr = i->second->run_next();
+        test_result tr = i->second->run_next(skip_test_id);
+
        callback_->test_completed(tr);
 
if( tr.result == test_result::ex_ctor )
@@ -436,13 +458,11 @@
    }
  };
 
-  namespace
-  {
    /**
      * Tests provided condition.
      * Throws if false.
      */
-    void ensure(bool cond)
+    inline void ensure(bool cond)
    {
        if( !cond ) throw failure("");
    }
@@ -511,10 +531,19 @@
    /**
      * Unconditionally fails with message.
      */
-    void fail(const char* msg="")
+ template <class T>
+    void fail(const T msg)
    {
      throw failure(msg);
    }
+
+    /**
+    * Unconditionally fails with message.
+    */
+ template <class T>
+    void skip_fail(const T msg)
+    {
+      throw skip_failure(msg);
  }
 
  /**
@@ -705,7 +734,7 @@
    /**
      * Runs next test.
      */
-    test_result run_next()
+    test_result run_next(int skip_test_id = 0)
    {
      if( current_test_ == tests_.end() )
      {
@@ -718,8 +747,17 @@
      {
        try
        {
+          if (current_test_->first == skip_test_id)
+          {
+              test_result tr(name_,current_test_->first,test_result::skip);
+              current_test_++;
+              return tr;
+          }
+          else
+          {
          return run_test_(current_test_++,obj);
        }
+        }
        catch( const no_such_test& )
        {
          continue;
@@ -774,6 +812,12 @@
        test_result tr(name_,ti->first,test_result::fail,ex);
        return tr;
      }
+      catch(const skip_failure& ex)
+      {
+        // test failed because of ensure() or similar method
+        test_result tr(name_,ti->first,test_result::skip_fail,ex);
+        return tr;
+      }
      catch(const seh& ex)
      {
        // test failed with sigsegv, divide by zero, etc
</pre>


Save this patch as tut.patch in the same directory as tut.h and apply it from a terminal program like xterm or cygwin with the command:
<pre>
$ patch -p1 < tut.patch
</pre>
= TUT-2008-11-30 =
Internally, TUT has been migrated to the 2008-11-30. This patch will not work against the current code, but is expected to be in use soon.


<pre>
<pre>
--- tut.orig/tut_assert.hpp 2008-12-05 17:35:10.000000000 -0800
diff -r 12b2ceb31753 tut/tut_assert.hpp
+++ tut.new/tut_assert.hpp 2008-12-05 17:37:56.000000000 -0800
--- a/tut/tut_assert.hpp Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_assert.hpp Tue Jul 21 15:37:32 2009 -0700
@@ -154,9 +154,23 @@
@@ -154,9 +154,23 @@
     throw failure(msg);
     throw failure(msg);
Line 203: Line 46:
  #endif
  #endif
   
   
diff -u tut.orig/tut_exception.hpp tut.new/tut_exception.hpp
diff -r 12b2ceb31753 tut/tut_exception.hpp
--- tut.orig/tut_exception.hpp 2008-12-05 17:35:10.000000000 -0800
--- a/tut/tut_exception.hpp Tue Jul 21 15:09:02 2009 -0700
+++ tut.new/tut_exception.hpp 2008-12-05 17:37:56.000000000 -0800
+++ b/tut/tut_exception.hpp Tue Jul 21 15:37:32 2009 -0700
@@ -201,6 +201,26 @@
@@ -201,6 +201,26 @@
     const test_result tr;
     const test_result tr;
Line 233: Line 76:
   
   
  #endif
  #endif
diff -u tut.orig/tut_result.hpp tut.new/tut_result.hpp
diff -r 12b2ceb31753 tut/tut_posix.hpp
--- tut.orig/tut_result.hpp 2008-12-05 17:35:10.000000000 -0800
--- a/tut/tut_posix.hpp Tue Jul 21 15:09:02 2009 -0700
+++ tut.new/tut_result.hpp 2008-12-05 17:37:56.000000000 -0800
+++ b/tut/tut_posix.hpp Tue Jul 21 15:37:32 2009 -0700
@@ -248,13 +248,13 @@
                    return;
                }
                else
-            {
-                std::stringstream ss;
+                {
+                    std::stringstream ss;
                    char e[1024];
                    ss << "child " << pid << " could not be killed with SIGKILL, " << strerror_r(errno, e, sizeof(e)) << std::endl;
-                fail(ss.str());
+                    fail(ss.str());
+                }
            }
-        }
            ensure_equals("wait after SIGKILL", waitpid_(pid, &status), pid);
            ensure_child_signal_(status, SIGKILL);
diff -r 12b2ceb31753 tut/tut_result.hpp
--- a/tut/tut_result.hpp Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_result.hpp Tue Jul 21 15:37:32 2009 -0700
@@ -51,6 +51,7 @@
@@ -51,6 +51,7 @@
       * ex - test throwed an exceptions
       * ex - test throwed an exceptions
Line 253: Line 117:
     };
     };
   
   
     result_type result;
     result_type result;</pre>


</pre>


Save this patch as <code>tut.patch</code> in the <code>tut-2008-11-30/tut</code> directory - alongside the <code>tut_assert.hpp</code>, <code>tut_exception.hpp</code>, and <code>tut_result.hpp</code> files - and apply it from a terminal program like xterm or cygwin with the command:  
[[Category:Compiling viewer]]
 
  $ patch -p1 < tut.patch

Latest revision as of 05:39, 15 July 2010

Using Linden Lab's modified version

Linden Lab's modified version can be downloaded with

scripts/install.py tut

which uses install.xml in the source tree for the right version/download-url.

Using the original source

The original source can be downloaded from http://downloads.sourceforge.net/sourceforge/tut-framework/tut-2008-11-30.tar.gz

Our unit test framework did not have any method for skipping tests. Sometimes known failure cases are found which require temporarily skipping tests. The following patch adds that functionality.

Patch against tut-2008-11-30.tar.gz . Save this patch as tut.patch in the tut-2008-11-30 directory and apply it from a terminal program like xterm or cygwin with the command:

 $ patch -p1 < tut.patch


diff -r 12b2ceb31753 tut/tut_assert.hpp
--- a/tut/tut_assert.hpp	Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_assert.hpp	Tue Jul 21 15:37:32 2009 -0700
@@ -154,9 +154,23 @@
     throw failure(msg);
 }
 
+/**
+ * Skip test because of known failure.
+ */
+void skip(const char* msg = "")
+{
+    throw skip_failure(msg);
+}
+
+void skip(const std::string& msg)
+{
+    throw skip_failure(msg);
+}
+
 } // end of namespace
 
 }
 
+
 #endif
 
diff -r 12b2ceb31753 tut/tut_exception.hpp
--- a/tut/tut_exception.hpp	Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_exception.hpp	Tue Jul 21 15:37:32 2009 -0700
@@ -201,6 +201,26 @@
     const test_result tr;
 };
 
+/**
+ * Exception to be throwed when skip_fail() is called.
+ */
+struct skip_failure : public failure
+{
+    skip_failure(const std::string& msg) 
+        : failure(msg) 
+    {
+    }
+
+    test_result::result_type result() const
+    {
+        return test_result::skip;
+    }
+
+    ~skip_failure() throw()
+    {
+    }
+};
+
 }
 
 #endif
diff -r 12b2ceb31753 tut/tut_posix.hpp
--- a/tut/tut_posix.hpp	Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_posix.hpp	Tue Jul 21 15:37:32 2009 -0700
@@ -248,13 +248,13 @@
                     return;
                 }
                 else
-            {
-                std::stringstream ss;
+                {
+                    std::stringstream ss;
                     char e[1024];
                     ss << "child " << pid << " could not be killed with SIGKILL, " << strerror_r(errno, e, sizeof(e)) << std::endl;
-                fail(ss.str());
+                    fail(ss.str());
+                }
             }
-        }
 
             ensure_equals("wait after SIGKILL", waitpid_(pid, &status), pid);
             ensure_child_signal_(status, SIGKILL);
diff -r 12b2ceb31753 tut/tut_result.hpp
--- a/tut/tut_result.hpp	Tue Jul 21 15:09:02 2009 -0700
+++ b/tut/tut_result.hpp	Tue Jul 21 15:37:32 2009 -0700
@@ -51,6 +51,7 @@
      * ex - test throwed an exceptions
      * warn - test finished successfully, but test destructor throwed
      * term - test forced test application to terminate abnormally
+     * skip - test skpped because it is a known failure case
      */
     enum result_type
     {
@@ -60,7 +61,8 @@
         warn,
         term,
         ex_ctor,
-        rethrown
+        rethrown,
+        skip,
     };
 
     result_type result;