Commits

Bob Swift committed 70b1813

GINT-56: getOutData function, expand searchForId, fix a minor helper bug with null workingTarget value

Comments (0)

Files changed (3)

src/main/groovy/org/swift/tools/Gint.groovy

     }
 
     /**
+     * Get outData for a testcase. Handles initializing to an empty list if null. Convenience for users
+     * @param testcase (not null)
+     * @return list of strings
+     */
+    public List getOutData(final Map<String, Object> testcase) {
+        if (testcase?.outData == null) {
+            assert testcase // testcase cannot be null
+            testcase.outData = []
+        }
+        return testcase.outData
+    }
+
+    /**
      * Add testcase
      * @param testcase
      */
                 } catch (Exception exception) {
                     message 'error', testcase.name + ': ' + exception.toString()
                     testcase.result = FAIL_EXCEPTION
-                    testcase.outData = []
-                    testcase.outData << exception.getMessage()
-                    testcase.outData << exception.getStackTrace().toString()
+                    getOutData(testcase) << exception.getMessage()
+                    getOutData(testcase) << exception.getStackTrace().toString()
                     if (getVerbose()) {
                         exception.printStackTrace()
                     }
                 } catch (Error error) {  // primarily for assertion failures or other errors
                     message 'error', testcase.name + ': ' + error.toString()
                     testcase.result = FAIL_ASSERTION
-                    testcase.outData = []
-                    testcase.outData << error.getMessage()  // log the assertion failure data
+                    getOutData(testcase) << error.getMessage()  // log the assertion failure data
                     if (!error.toString().contains('assert')) { // don't do assert stack traces - just noise
-                        testcase.outData << error.getStackTrace()
+                        getOutData(testcase) << error.getStackTrace()
                         if (getVerbose()) {
                             error.printStackTrace()
                         }
 
             } catch (Error error) {  // primarily for assertion failures or other errors
                 addTestFailedMessage("Closure for testcase ${testcase.name} generated error: " + error.toString())
-                if (testcase.outData == null) {
-                    testcase.outData = []
-                }
-                testcase.outData << error.getMessage()  // log the assertion failure data
+                getOutData(testcase) << error.getMessage()  // log the assertion failure data
                 if (!error.toString().contains('assert')) { // don't do assert stack traces - just noise
-                    testcase.outData << error.getStackTrace()
+                    getOutData(testcase) << error.getStackTrace()
                     if (getVerbose()) {
                         error.printStackTrace()
                     }
         def patternFlag = ((testcase.patternFlag != null) ? testcase.patternFlag : getPatternFlag())
         if (testcase.success && testcase.data) {
             // enable multi-line pattern matching
-            outDataAsString = helper.listToSeparatedString(testcase.outData, System.properties.'line.separator')
+            outDataAsString = helper.listToSeparatedString(getOutData(testcase), System.properties.'line.separator')
             testcase.found = helper.verifySearchInTarget(search: testcase.data, target: outDataAsString, patternFlag: patternFlag, logFailure: true, firstParameter: testcase)
             testcase.success = testcase.found
         }
         // look for fail data
         if (testcase.success && testcase.failData) {
             if (outDataAsString == null) {
-                outDataAsString = helper.listToSeparatedString(testcase.outData, System.properties.'line.separator')
+                outDataAsString = helper.listToSeparatedString(getOutData(testcase), System.properties.'line.separator')
             }
             testcase.notFound = helper.verifySearchNotInTarget(search: testcase.failData, target: outDataAsString, patternFlag: patternFlag, logFailure: true, firstParameter: testcase)
             testcase.success = testcase.notFound
                     // check to see if we should do the retry based on retryData (just like matching on data for result)
                     // all retryData must be found
                     if (outDataAsString == null) {
-                        outDataAsString = helper.listToSeparatedString(testcase.outData, System.properties.'line.separator')
+                        outDataAsString = helper.listToSeparatedString(getOutData(testcase), System.properties.'line.separator')
                     }
                     doRetry = helper.verifySearchInTarget(search: testcase.retryData, target: outDataAsString, patternFlag: patternFlag, logFailure: true, firstParameter: testcase)
                     if (!doRetry && getVerbose()) {
                     // check to see if we should do cancel retry based on retryCancelData (just like matching on failData for result)
                     // any retryCancelData found will cancel the retry
                     if (outDataAsString == null) {
-                        outDataAsString = helper.listToSeparatedString(testcase.outData, System.properties.'line.separator')
+                        outDataAsString = helper.listToSeparatedString(getOutData(testcase), System.properties.'line.separator')
                     }
                     doRetry = helper.verifySearchNotInTarget(search: testcase.retryCancelData, target: outDataAsString, patternFlag: patternFlag, logFailure: true, firstParameter: testcase)
                     if (!doRetry && getVerbose()) {

src/main/groovy/org/swift/tools/GintForAtlassian.groovy

     }
 
     /**
-     * Look for an id in data, looks for pattern like (12345) or id: 12345 or id 12345 or id=12345
+     * Look for an id in data, looks for pattern like (12345) or id: 12345 or id 12345 or id=12345 or . : 12345
      * @param data - data to be searched
      * @param occurrance - 1 based, 1 is first occurrence (default), 2 is second occurrence
      * @return id or null
      */
     static public String searchForId(final data, final occurrence = 1) {
-        def matcher = (data.toString() =~ /(?:\((\d+)\))|(?:id[:=]{0,1} {0,1}(\d+))/)
-        for (int i = 1; i < occurrence && matcher.find(); i++) {
+        def matcher = (data.toString() =~ /(?:\((\d+)\))|(?:id[:=]{0,1} {0,1}(\d+)|(?:\. : (\d+)))/)
+        for (int i = 1; i < occurrence && matcher.find(); i++) { // skip earlier occurrances
         }
-        return (matcher.find() ? matcher.group(1) ?: matcher.group(2) : null)
+        return (matcher.find() ? matcher.group(1) ?: matcher.group(2) ?: matcher.group(3) : null)
     }
 
     /**

src/main/groovy/org/swift/tools/Helper.groovy

                         if (map.ordered == true) {
                             def endIndex = [
                                 200,
-                                map?.workingTarget.size()
+                                map?.workingTarget?.size()
                             ].min()
-                            message 'info', "Ordered search started at (${map?.workingTarget.size()} characters remaining): ${map?.workingTarget?.substring(0, endIndex)}"
+                            message 'info', "Ordered search started at (${map?.workingTarget?.size()} characters remaining): ${map?.workingTarget?.substring(0, endIndex)}"
                         }
                     }
                     return false // any single failure is a failure for all