Unverified 提交 a7c139bd authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1679 from katzyn/tests

Use TestScript for testSimple
...@@ -194,7 +194,6 @@ ...@@ -194,7 +194,6 @@
<testResource> <testResource>
<directory>src/test</directory> <directory>src/test</directory>
<includes> <includes>
<include>org/h2/test/scripts/testSimple.in.txt</include>
<include>org/h2/test/scripts/**/*.sql</include> <include>org/h2/test/scripts/**/*.sql</include>
<include>org/h2/samples/newsfeed.sql</include> <include>org/h2/samples/newsfeed.sql</include>
<include>org/h2/samples/optimizations.sql</include> <include>org/h2/samples/optimizations.sql</include>
......
...@@ -216,8 +216,7 @@ If you'd like to contribute bug fixes or new features, please consider the follo ...@@ -216,8 +216,7 @@ If you'd like to contribute bug fixes or new features, please consider the follo
The formatting options (<code>eclipseCodeStyle</code>) are also included. The formatting options (<code>eclipseCodeStyle</code>) are also included.
</li><li>Please provide test cases and integrate them into the test suite. </li><li>Please provide test cases and integrate them into the test suite.
For Java level tests, see <code>src/test/org/h2/test/TestAll.java</code>. For Java level tests, see <code>src/test/org/h2/test/TestAll.java</code>.
For SQL level tests, see <code>src/test/org/h2/test/test.in.txt</code> or For SQL level tests, see SQL files in <code>src/test/org/h2/test/scripts</code>.
<code>testSimple.in.txt</code>.
</li><li>The test cases should cover at least 90% of the changed and new code; </li><li>The test cases should cover at least 90% of the changed and new code;
use a code coverage tool to verify that (see above). use a code coverage tool to verify that (see above).
or use the build target <code>coverage</code>. or use the build target <code>coverage</code>.
......
...@@ -489,16 +489,7 @@ public abstract class Value extends VersionedValue { ...@@ -489,16 +489,7 @@ public abstract class Value extends VersionedValue {
*/ */
public static TypeInfo getHigherType(TypeInfo type1, TypeInfo type2) { public static TypeInfo getHigherType(TypeInfo type1, TypeInfo type2) {
int t1 = type1.getValueType(), t2 = type2.getValueType(); int t1 = type1.getValueType(), t2 = type2.getValueType();
if (t1 == Value.UNKNOWN || t2 == Value.UNKNOWN) { int dataType = getHigherOrder(t1, t2);
if (t1 == t2) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "?, ?");
} else if (t1 == Value.NULL) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "NULL, ?");
} else if (t2 == Value.NULL) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, "?, NULL");
}
}
int dataType = getOrder(t1) > getOrder(t2) ? t1 : t2;
long precision = Math.max(type1.getPrecision(), type2.getPrecision()); long precision = Math.max(type1.getPrecision(), type2.getPrecision());
int scale = Math.max(type1.getScale(), type2.getScale()); int scale = Math.max(type1.getScale(), type2.getScale());
ExtTypeInfo ext1 = type1.getExtTypeInfo(); ExtTypeInfo ext1 = type1.getExtTypeInfo();
......
...@@ -125,7 +125,6 @@ import org.h2.test.poweroff.TestReorderWrites; ...@@ -125,7 +125,6 @@ import org.h2.test.poweroff.TestReorderWrites;
import org.h2.test.recover.RecoverLobTest; import org.h2.test.recover.RecoverLobTest;
import org.h2.test.rowlock.TestRowLocks; import org.h2.test.rowlock.TestRowLocks;
import org.h2.test.scripts.TestScript; import org.h2.test.scripts.TestScript;
import org.h2.test.scripts.TestScriptSimple;
import org.h2.test.server.TestAutoServer; import org.h2.test.server.TestAutoServer;
import org.h2.test.server.TestInit; import org.h2.test.server.TestInit;
import org.h2.test.server.TestNestedLoop; import org.h2.test.server.TestNestedLoop;
...@@ -742,7 +741,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -742,7 +741,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
beforeTest(); beforeTest();
// db // db
addTest(new TestScriptSimple());
addTest(new TestScript()); addTest(new TestScript());
addTest(new TestAlter()); addTest(new TestAlter());
addTest(new TestAlterSchemaRename()); addTest(new TestAlterSchemaRename());
......
...@@ -122,6 +122,9 @@ public class TestScript extends TestDb { ...@@ -122,6 +122,9 @@ public class TestScript extends TestDb {
reconnectOften = !config.memory && config.big; reconnectOften = !config.memory && config.big;
testScript("testScript.sql"); testScript("testScript.sql");
if (!config.memory && !config.big && !config.networked) {
testScript("testSimple.sql");
}
testScript("comments.sql"); testScript("comments.sql");
testScript("derived-column-names.sql"); testScript("derived-column-names.sql");
testScript("distinct.sql"); testScript("distinct.sql");
......
/*
* Copyright 2004-2019 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.scripts;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
import org.h2.util.ScriptReader;
/**
* This test runs a simple SQL script file and compares the output with the
* expected output.
*/
public class TestScriptSimple extends TestDb {
private Connection conn;
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
@Override
public boolean isEnabled() {
if (config.memory || config.big || config.networked) {
return false;
}
return true;
}
@Override
public void test() throws Exception {
deleteDb("scriptSimple");
reconnect();
String inFile = "org/h2/test/scripts/testSimple.in.txt";
InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(is, StandardCharsets.UTF_8));
try (ScriptReader reader = new ScriptReader(lineReader)) {
while (true) {
String sql = reader.readStatement();
if (sql == null) {
break;
}
sql = sql.trim();
try {
if ("@reconnect".equals(sql.toLowerCase())) {
reconnect();
} else if (sql.length() == 0) {
// ignore
} else if (sql.toLowerCase().startsWith("select")) {
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next()) {
String expected = reader.readStatement().trim();
String got = "> " + rs.getString(1);
assertEquals(sql, expected, got);
}
} else {
conn.createStatement().execute(sql);
}
} catch (SQLException e) {
System.out.println(sql);
throw e;
}
}
}
conn.close();
deleteDb("scriptSimple");
}
private void reconnect() throws SQLException {
if (conn != null) {
conn.close();
}
conn = getConnection("scriptSimple");
}
}
...@@ -215,7 +215,7 @@ public class TestFileSystem extends TestDb { ...@@ -215,7 +215,7 @@ public class TestFileSystem extends TestDb {
} }
private void testClasspath() throws IOException { private void testClasspath() throws IOException {
String resource = "org/h2/test/scripts/testSimple.in.txt"; String resource = "org/h2/test/scripts/testSimple.sql";
InputStream in; InputStream in;
in = getClass().getResourceAsStream("/" + resource); in = getClass().getResourceAsStream("/" + resource);
assertNotNull(in); assertNotNull(in);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论