Unverified 提交 c628a91c authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #857 from katzyn/tests

Do not write each SQL error multiple times in TestScript
...@@ -464,6 +464,17 @@ public abstract class TestBase { ...@@ -464,6 +464,17 @@ public abstract class TestBase {
throw new AssertionError(string); throw new AssertionError(string);
} }
/**
* Log an error message.
*
* @param s the message
*/
public static void logErrorMessage(String s) {
System.out.flush();
System.err.println("ERROR: " + s + "------------------------------");
logThrowable(s, null);
}
/** /**
* Log an error message. * Log an error message.
* *
...@@ -478,6 +489,10 @@ public abstract class TestBase { ...@@ -478,6 +489,10 @@ public abstract class TestBase {
System.err.println("ERROR: " + s + " " + e.toString() System.err.println("ERROR: " + s + " " + e.toString()
+ " ------------------------------"); + " ------------------------------");
e.printStackTrace(); e.printStackTrace();
logThrowable(null, e);
}
private static void logThrowable(String s, Throwable e) {
// synchronize on this class, because file locks are only visible to // synchronize on this class, because file locks are only visible to
// other JVMs // other JVMs
synchronized (TestBase.class) { synchronized (TestBase.class) {
...@@ -494,9 +509,14 @@ public abstract class TestBase { ...@@ -494,9 +509,14 @@ public abstract class TestBase {
} }
// append // append
FileWriter fw = new FileWriter("error.txt", true); FileWriter fw = new FileWriter("error.txt", true);
if (s != null) {
fw.write(s);
}
if (e != null) {
PrintWriter pw = new PrintWriter(fw); PrintWriter pw = new PrintWriter(fw);
e.printStackTrace(pw); e.printStackTrace(pw);
pw.close(); pw.close();
}
fw.close(); fw.close();
// unlock // unlock
lock.release(); lock.release();
......
...@@ -41,6 +41,7 @@ public class TestScript extends TestBase { ...@@ -41,6 +41,7 @@ public class TestScript extends TestBase {
private boolean reconnectOften; private boolean reconnectOften;
private Connection conn; private Connection conn;
private Statement stat; private Statement stat;
private String fileName;
private LineNumberReader in; private LineNumberReader in;
private int outputLineNo; private int outputLineNo;
private PrintStream out; private PrintStream out;
...@@ -155,6 +156,7 @@ public class TestScript extends TestBase { ...@@ -155,6 +156,7 @@ public class TestScript extends TestBase {
// we processed. // we processed.
conn = null; conn = null;
stat = null; stat = null;
fileName = null;
in = null; in = null;
outputLineNo = 0; outputLineNo = 0;
out = null; out = null;
...@@ -172,7 +174,7 @@ public class TestScript extends TestBase { ...@@ -172,7 +174,7 @@ public class TestScript extends TestBase {
conn.close(); conn.close();
out.close(); out.close();
if (errors.length() > 0) { if (errors.length() > 0) {
throw new Exception("errors:\n" + errors.toString()); throw new Exception("errors in " + scriptFileName + " found");
} }
// new File(outFile).delete(); // new File(outFile).delete();
} }
...@@ -200,6 +202,7 @@ public class TestScript extends TestBase { ...@@ -200,6 +202,7 @@ public class TestScript extends TestBase {
if (is == null) { if (is == null) {
throw new IOException("could not find " + inFile); throw new IOException("could not find " + inFile);
} }
fileName = inFile;
in = new LineNumberReader(new InputStreamReader(is, "Cp1252")); in = new LineNumberReader(new InputStreamReader(is, "Cp1252"));
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
while (true) { while (true) {
...@@ -435,17 +438,14 @@ public class TestScript extends TestBase { ...@@ -435,17 +438,14 @@ public class TestScript extends TestBase {
if (reconnectOften && sql.toUpperCase().startsWith("EXPLAIN")) { if (reconnectOften && sql.toUpperCase().startsWith("EXPLAIN")) {
return; return;
} }
errors.append("line: "); errors.append(fileName).append('\n');
errors.append(outputLineNo); errors.append("line: ").append(outputLineNo).append('\n');
errors.append("\n" + "exp: "); errors.append("exp: ").append(compare).append('\n');
errors.append(compare); errors.append("got: ").append(s).append('\n');
errors.append("\n" + "got: ");
errors.append(s);
errors.append("\n");
if (e != null) { if (e != null) {
TestBase.logError("script", e); TestBase.logError("script", e);
} }
TestBase.logError(errors.toString(), null); TestBase.logErrorMessage(errors.toString());
if (failFast) { if (failFast) {
conn.close(); conn.close();
System.exit(1); System.exit(1);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论