From 90016c793924aedb38d93134e6f81112c421c568 Mon Sep 17 00:00:00 2001
From: Reid Spencer <rspencer@reidspencer.com>
Date: Sat, 14 Apr 2007 19:37:22 +0000
Subject: [PATCH] For PR1319: More improvements: 1. Using ::errorInfo wasn't
 such a hot idea. Go back to just printing the    offending line of code and
 the stderr output. This is sufficient and    not entangled with Tcl goop. 2.
 Capture the problem report numbers and report them whether pass or fail.   
 This helps quickly get some context when a test fails, if it has an   
 associated PR number.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36010 91177308-0d34-0410-b5e6-96231b3b80d8
---
 test/lib/llvm.exp | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/test/lib/llvm.exp b/test/lib/llvm.exp
index acfc911565e..c5d4ffe9bfe 100644
--- a/test/lib/llvm.exp
+++ b/test/lib/llvm.exp
@@ -1,11 +1,14 @@
-proc execOneLine { test outcome lineno line } {
+proc execOneLine { test PRS outcome lineno line } {
   set status 0
   set resultmsg ""
   set retval [ catch { eval exec -keepnewline -- $line } errmsg ]
   if { $retval != 0 } {
     set code [lindex $::errorCode 0]
     set lineno [expr $lineno + 1]
-    set errmsg " at RUN: line $lineno\n$::errorInfo"
+    if { $PRS != ""} {
+      set PRS " for $PRS" 
+    }
+    set errmsg " at line $lineno$PRS\nwhile running: $line\n$errmsg"
     switch "$code" {
       CHILDSTATUS {
         set status [lindex $::errorCode 2]
@@ -96,19 +99,34 @@ proc llvm-runtest { programs } {
     # Open the test file and start reading lines
     set testFileId [ open $test r]
     set runline ""
+    set PRNUMS ""
     foreach line [split [read $testFileId] \n] {
 
-      #see if this is our run line
+      # if its the END. line then stop parsing (optimization for big files)
       if {[regexp {END.[ *]$} $line match endofscript]} {
         break
+
+      # if the line is continued, concatente and continue the loop
       } elseif {[regexp {RUN: *([^\\]+)(\\)$} $line match oneline suffix]} {
         set runline "$runline$oneline "
+
+      # if its a terminating RUN: line then do substitution on the whole line
+      # and then save the line.
       } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
         set runline "$runline$oneline"
         set runline [ substitute $runline $test $tmpFile ]
         set lines($numLines) $runline
         set numLines [expr $numLines + 1]
         set runline ""
+
+      # if its an PR line, save the problem report number
+      } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
+        if {$PRNUMS == ""} {
+          set PRNUMS $prnum
+        } else {
+          set PRNUMS "$PRNUMS,$prnum"
+        }
+      # if its an XFAIL line, see if we should be XFAILing or not.
       } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
         set targets
 
@@ -138,7 +156,7 @@ proc llvm-runtest { programs } {
       for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
         regsub ^.*RUN:(.*) $lines($i) \1 theLine
         set theLine [subst $theLine ]
-        set resultmsg [execOneLine $test $outcome $i $theLine ]
+        set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
         if { $resultmsg != "" } {
           if { $outcome == "XFAIL" } {
             xfail "$resultmsg"
@@ -150,10 +168,13 @@ proc llvm-runtest { programs } {
         }
       }
       if { !$failed } {
+        if {$PRNUMS != ""} {
+          set PRNUMS " for $PRNUMS"
+        }
         if { $outcome == "XFAIL" } {
-          xpass "$test"
+          xpass "$test$PRNUMS"
         } else {
-          pass "$resultmsg"
+          pass "$test$PRNUMS"
         }
       }
     }