1 11 package org.eclipse.test; 12 13 import java.io.BufferedOutputStream ; 14 import java.io.File ; 15 import java.io.FileInputStream ; 16 import java.io.FileOutputStream ; 17 import java.io.IOException ; 18 import java.io.PrintStream ; 19 import java.util.StringTokenizer ; 20 import java.io.ByteArrayOutputStream ; 21 22 25 public class RegressionTest { 26 27 PrintStream output; 28 String oldFilename, newFilename, outFilename; 29 public static final String NOTHING_CHANGED_MSG 30 = "All tests unchanged."; 31 34 public RegressionTest( String oldFilename, 35 String newFilename, 36 String outFilename) { 37 this.oldFilename = oldFilename; 38 this.newFilename = newFilename; 39 this.outFilename = outFilename; 40 } 41 42 public static void main(String [] argv) { 43 if (argv.length < 3) { 44 System.err.println("Error: too few arguments"); 45 System.err.println("Usage: (progname) oldfile newfile outfile"); 46 } else { 47 RegressionTest rt = new RegressionTest(argv[0], argv[1], argv[2]); 49 rt.testRegressions(); 50 } 51 } 52 53 56 public void testRegressions() { 57 String oldPass = ""; 59 String newPass = ""; 60 try { 61 oldPass = readFile(oldFilename); 62 newPass = readFile(newFilename); 63 } catch (Exception e) { 64 System.err.println("Error opening input file"); 65 System.err.println(e.getMessage()); 66 System.exit(-1); 67 } 68 69 try { 70 output = new PrintStream ( 71 new BufferedOutputStream ( 72 new FileOutputStream ( 73 new File (outFilename)))); 74 } catch (Exception e) { 75 System.err.println("Error opening output file"); 76 System.err.println(e.getMessage()); 77 System.exit(-1); 78 } 79 StringTokenizer oldst = new StringTokenizer (oldPass); 81 StringTokenizer newst = new StringTokenizer (newPass); 82 83 String [] oldTest = nextTest(oldst); 84 String [] newTest = nextTest(newst); 85 86 boolean nothingChanged = true; 87 while (oldTest != null && newTest != null) { 88 89 int compareName = oldTest[0].compareTo(newTest[0]); 91 if (compareName == 0) { 92 int compareStatus = oldTest[1].compareTo(newTest[1]); 93 if (compareStatus != 0) { 94 nothingChanged = false; 95 output.println(testChanged(newTest)); 96 } 97 oldTest = nextTest(oldst); 98 newTest = nextTest(newst); 99 } else if (compareName < 0) { 100 output.println(testNotRun(oldTest)); 102 oldTest = nextTest(oldst); 103 nothingChanged = false; 104 } else { 105 output.println(testAdded(newTest)); 107 newTest = nextTest(newst); 108 nothingChanged = false; 109 } 110 } 111 while (oldTest != null) { 113 output.println(testNotRun(oldTest)); 115 oldTest = nextTest(oldst); 116 nothingChanged = false; 117 } 118 while (newTest != null) { 119 output.println(testAdded(newTest)); 121 newTest = nextTest(newst); 122 nothingChanged = false; 123 } 124 if (nothingChanged) { 126 output.println(NOTHING_CHANGED_MSG); 127 } 128 output.close(); 129 } 130 131 134 static String testNotRun(String [] test) { 135 return "Not run: " + test[0]; 136 } 137 138 141 static String testChanged(String [] test) { 142 return "Changed: " + test[0] + ", " + test[1]; 143 } 144 145 148 static String testAdded(String [] test) { 149 return "New test: " + test[0] + ", Status: " + test[1]; 150 } 151 152 155 static String readFile(String s) throws IOException { 156 byte[] buf = new byte[8192]; 157 FileInputStream r = new FileInputStream (s); 158 ByteArrayOutputStream aStream = new ByteArrayOutputStream (); 159 int n; 160 while ((n = r.read(buf)) != -1) { 161 aStream.write(buf, 0, n); 162 } 163 r.close(); 164 return aStream.toString(); 165 } 166 167 168 172 static String [] nextTest(StringTokenizer st) { 173 String [] test = new String [2]; 174 if (st.hasMoreTokens()) { 175 test[0] = st.nextToken(); 176 } else { 177 return null; 178 } 179 if (st.hasMoreTokens()) { 180 test[1] = st.nextToken(); 181 } else { 182 return null; 183 } 184 return test; 185 } 186 } 187 188 | Popular Tags |