Bump to gtest 1.10.0
[platform/upstream/gtest.git] / googletest / test / gtest_json_test_utils.py
old mode 100755 (executable)
new mode 100644 (file)
similarity index 58%
rename from xcode/Scripts/runtests.sh
rename to googletest/test/gtest_json_test_utils.py
index 3fc229f..62bbfc2
@@ -1,6 +1,4 @@
-#!/bin/bash
-#
-# Copyright 2008, Google Inc.
+# Copyright 2018, Google Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-# Executes the samples and tests for the Google Test Framework.
+"""Unit test utilities for gtest_json_output."""
+
+import re
 
-# Help the dynamic linker find the path to the libraries.
-export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR
-export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR
 
-# Create some executables.
-test_executables=("$BUILT_PRODUCTS_DIR/gtest_unittest-framework"
-                  "$BUILT_PRODUCTS_DIR/gtest_unittest"
-                  "$BUILT_PRODUCTS_DIR/sample1_unittest-framework"
-                  "$BUILT_PRODUCTS_DIR/sample1_unittest-static")
+def normalize(obj):
+  """Normalize output object.
 
-# Now execute each one in turn keeping track of how many succeeded and failed. 
-succeeded=0
-failed=0
-failed_list=()
-for test in ${test_executables[*]}; do
-  "$test"
-  result=$?
-  if [ $result -eq 0 ]; then
-    succeeded=$(( $succeeded + 1 ))
-  else
-    failed=$(( failed + 1 ))
-    failed_list="$failed_list $test"
-  fi
-done
+  Args:
+     obj: Google Test's JSON output object to normalize.
 
-# Report the successes and failures to the console.
-echo "Tests complete with $succeeded successes and $failed failures."
-if [ $failed -ne 0 ]; then
-  echo "The following tests failed:"
-  echo $failed_list
-fi
-exit $failed
+  Returns:
+     Normalized output without any references to transient information that may
+     change from run to run.
+  """
+  def _normalize(key, value):
+    if key == 'time':
+      return re.sub(r'^\d+(\.\d+)?s$', '*', value)
+    elif key == 'timestamp':
+      return re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$', '*', value)
+    elif key == 'failure':
+      value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
+      return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
+    else:
+      return normalize(value)
+  if isinstance(obj, dict):
+    return {k: _normalize(k, v) for k, v in obj.items()}
+  if isinstance(obj, list):
+    return [normalize(x) for x in obj]
+  else:
+    return obj