Skip to content

Feature request (and patch) : filter test on command line #76

Closed
@hsaturn

Description

@hsaturn

Hi Brian,

As I really need to run or debug only one test, I really miss the command line filtering option as it is possible with gtest.

So I've written this patch:

  • Because Test* are initialized before main() is called, I could not initialize mLifeCycle inside init() functions. The workaround was to wrap getLifeCycle.
  • I did not write a FilterTest just because I don't know how to unit test this feature :-(

I'd be cool to add this patch into the next release.

Best regards

diff --git a/src/aunit/Test.cpp b/src/aunit/Test.cpp
index c06f860..dae8f8e 100644
--- a/src/aunit/Test.cpp
+++ b/src/aunit/Test.cpp
@@ -70,6 +70,26 @@ void Test::insert() {
   *p = this;
 }
 
+uint8_t Test::getLifeCycle() const
+{
+  if (mLifeCycle != kLifeCycleFinished and not allowed())
+    return kLifeCycleExcluded;
+
+  return mLifeCycle;
+}
+
+bool Test::allowed() const
+{
+  if (epoxy_argc==1) return true;
+  const char* testName = getName().getCString();
+  for(int i=1; i<epoxy_argc; i++)
+  {
+    if (strstr(testName, epoxy_argv[i]) != NULL)
+      return true;
+  }
+  return false;
+}
+
 void Test::resolve() {
   const __FlashStringHelper* const TEST_STRING = F("Test ");
 
diff --git a/src/aunit/Test.h b/src/aunit/Test.h
index 9dbd54f..0fe1785 100644
--- a/src/aunit/Test.h
+++ b/src/aunit/Test.h
@@ -158,7 +158,7 @@ class Test {
     const internal::FCString& getName() const { return mName; }
 
     /** Get the life cycle state of the test. */
-    uint8_t getLifeCycle() const { return mLifeCycle; }
+    uint8_t getLifeCycle() const;
 
     void setLifeCycle(uint8_t state) { mLifeCycle = state; }
 
@@ -277,6 +277,9 @@ class Test {
     /** Get the verbosity. */
     uint8_t getVerbosity() const { return mVerbosity; }
 
+    /** Check if test is not filtered by the command line **/
+    bool allowed() const;
+
   private:
     // Disable copy-constructor and assignment operator
     Test(const Test&) = delete;


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions