Difference between revisions of "Patch TUT"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(10 intermediate revisions by 4 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 ==


WARNING: The patch applies to a pretty old TUT version: TUT-2006-11-04
Linden Lab's modified version can be downloaded with


<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
which uses <code>install.xml</code> in the source tree for the right version/download-url.
@@ -79,6 +79,15 @@
  };


  /**
== Using the original source ==
+  * 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;


    /**
The original source can be downloaded from http://downloads.sourceforge.net/sourceforge/tut-framework/tut-2008-11-30.tar.gz
@@ -168,7 +189,7 @@


    // execute tests iteratively
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 void rewind() = 0;
-    virtual test_result run_next() = 0;
+    virtual test_result run_next(int skip_test_id = 0) = 0;


    // execute one test
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:
    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 -p1 < tut.patch


      try
      {
-        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:
<pre>
-   void run_all_tests_in_group_(const_iterator i) const
diff -r 12b2ceb31753 tut/tut_assert.hpp
+   void run_all_tests_in_group_(const_iterator i, int skip_test_id = 0) const
--- 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
      i->second->rewind();
@@ -154,9 +154,23 @@
      for( ;; )
    throw failure(msg);
      {
}
-       test_result tr = i->second->run_next();
+        test_result tr = i->second->run_next(skip_test_id);
+/**
+ * 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)  
+    {
+    }
+
+
        callback_->test_completed(tr);
+    test_result::result_type result() const
 
+    {
if( tr.result == test_result::ex_ctor )
+       return test_result::skip;
@@ -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);
    }
+
+
+    /**
+    ~skip_failure() throw()
+    * Unconditionally fails with message.
+    */
+ template <class T>
+    void skip_fail(const T msg)
+    {
+    {
+     throw skip_failure(msg);
+   }
  }
+};
 
+
  /**
}
@@ -705,7 +734,7 @@
    /**
#endif
       * Runs next test.
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
       */
       */
-    test_result run_next()
    enum result_type
+    test_result run_next(int skip_test_id = 0)
     {
     {
      if( current_test_ == tests_.end() )
@@ -60,7 +61,8 @@
      {
         warn,
@@ -718,8 +747,17 @@
         term,
      {
         ex_ctor,
        try
-        rethrown
         {
+        rethrown,
+          if (current_test_->first == skip_test_id)
+        skip,
+          {
     };
+              test_result tr(name_,current_test_->first,test_result::skip);
+              current_test_++;
    result_type result;</pre>
+              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:
[[Category:Compiling viewer]]
 
<pre>
$ patch -p1 < tut.patch
</pre>

Latest revision as of 06: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;