提交 dc35938e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix newlines in test scripts

上级 58a8b8bf
......@@ -5,12 +5,14 @@
*/
package org.h2.test.scripts;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
......@@ -47,6 +49,8 @@ public class TestScript extends TestDb {
private static final String BASE_DIR = "org/h2/test/scripts/";
private static final boolean FIX_OUTPUT = false;
private static final Field COMMAND;
private static final Field PREPARED;
......@@ -232,7 +236,16 @@ public class TestScript extends TestDb {
if (statements == null) {
println("Running commands in " + scriptFileName);
}
final String outFile = "test.out.txt";
String outFile;
if (FIX_OUTPUT) {
outFile = scriptFileName;
int idx = outFile.lastIndexOf('/');
if (idx >= 0) {
outFile = outFile.substring(idx + 1);
}
} else {
outFile = "test.out.txt";
}
conn = getConnection("script");
stat = conn.createStatement();
out = new PrintStream(new FileOutputStream(outFile));
......@@ -240,10 +253,31 @@ public class TestScript extends TestDb {
testFile(BASE_DIR + scriptFileName);
conn.close();
out.close();
if (FIX_OUTPUT) {
File file = new File(outFile);
// If there are two trailing newline characters remove one
try (RandomAccessFile r = new RandomAccessFile(file, "rw")) {
byte[] separator = System.lineSeparator().getBytes(StandardCharsets.ISO_8859_1);
int separatorLength = separator.length;
long length = r.length() - (separatorLength * 2);
truncate: if (length >= 0) {
r.seek(length);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < separatorLength; j++) {
if (r.readByte() != separator[j]) {
break truncate;
}
}
}
r.setLength(length + separatorLength);
}
}
file.renameTo(new File("h2/src/test/org/h2/test/scripts/" + scriptFileName));
return;
}
if (errors.length() > 0) {
throw new Exception("errors in " + scriptFileName + " found");
}
// new File(outFile).delete();
}
private String readLine() throws IOException {
......@@ -253,6 +287,7 @@ public class TestScript extends TestDb {
private String readNextLine() throws IOException {
String s;
boolean comment = false;
while ((s = in.readLine()) != null) {
if (s.startsWith("#")) {
int end = s.indexOf('#', 1);
......@@ -276,18 +311,32 @@ public class TestScript extends TestDb {
switch (flag) {
case "mvStore":
if (config.mvStore == val) {
out.print("#" + (val ? '+' : '-') + flag + '#');
break;
} else {
if (FIX_OUTPUT) {
write("#" + (val ? '+' : '-') + flag + '#' + s);
}
continue;
}
default:
fail("Unknown flag \"" + flag + '\"');
}
} else if (s.startsWith("--")) {
write(s);
comment = true;
continue;
}
if (!FIX_OUTPUT) {
s = s.trim();
}
s = s.trim();
if (!s.isEmpty()) {
break;
}
if (comment) {
write("");
comment = false;
}
}
return s;
}
......@@ -322,14 +371,20 @@ public class TestScript extends TestDb {
} else {
switch (sql) {
case "@reconnect":
write(sql);
write("");
if (!config.memory) {
reconnect(conn.getAutoCommit());
}
break;
case "@reconnect on":
write(sql);
write("");
allowReconnect = true;
break;
case "@reconnect off":
write(sql);
write("");
allowReconnect = false;
break;
default:
......
......@@ -24,4 +24,3 @@ INSERT INTO user_group (ID) VALUES (1);
DELETE FROM user_group;
> update count: 1
......@@ -29,7 +29,6 @@ SELECT * FROM TEST ORDER BY ID;
> 3 3000
> rows (ordered): 2
UPDATE TEST SET V = 3 WHERE ID = 3;
> update count: 1
......
......@@ -480,7 +480,6 @@ SELECT G / 10 G1, G / 10 G2, SUM(T.V) S FROM TEST T GROUP BY G / 10, G / 10;
> 2 2 4
> rows: 2
SELECT G / 10 G1, G / 10 G2, SUM(T.V) S FROM TEST T GROUP BY G2;
> G1 G2 S
> -- -- -
......
......@@ -44,7 +44,6 @@ explain with recursive "r"(n) as (
select n from "r";
>> WITH RECURSIVE PUBLIC."r"(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC."r" /* PUBLIC."r".tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC."r" "r" /* null */
select sum(n) from (
with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3)
......@@ -80,6 +79,7 @@ select 0 from (
> 0
> -
> rows: 0
with
r0(n,k) as (select -1, 0),
r1(n,k) as ((select 1, 0) union all (select n+1,k+1 from r1 where n <= 3)),
......
......@@ -23,7 +23,6 @@ select count(*), count(*) filter (where v >= 4) from test;
> 13 9
> rows: 1
select count(*), count(*) filter (where v >= 4) from test where v <= 10;
> COUNT(*) COUNT(*) FILTER (WHERE (V >= 4))
> -------- --------------------------------
......
......@@ -14,4 +14,3 @@ select acos(null) vn, acos(-1) r1 from test;
> ---- -----------------
> null 3.141592653589793
> rows: 1
......@@ -14,4 +14,3 @@ select asin(null) vn, asin(-1) r1 from test;
> ---- -------------------
> null -1.5707963267948966
> rows: 1
......@@ -14,4 +14,3 @@ select atan(null) vn, atan(-1) r1 from test;
> ---- -------------------
> null -0.7853981633974483
> rows: 1
......@@ -14,5 +14,3 @@ select atan2(null, null) vn, atan2(10, 1) r1 from test;
> ---- ------------------
> null 1.4711276743037347
> rows: 1
......@@ -14,7 +14,3 @@ select bitand(null, 1) vn, bitand(1, null) vn1, bitand(null, null) vn2, bitand(3
> ---- ---- ---- --
> null null null 2
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,7 +14,3 @@ select bitor(null, 1) vn, bitor(1, null) vn1, bitor(null, null) vn2, bitor(3, 6)
> ---- ---- ---- --
> null null null 7
> rows: 1
......@@ -14,7 +14,3 @@ select bitxor(null, 1) vn, bitxor(1, null) vn1, bitxor(null, null) vn2, bitxor(3
> ---- ---- ---- --
> null null null 5
> rows: 1
......@@ -14,8 +14,3 @@ select ceil(null) vn, ceil(1) v1, ceiling(1.1) v2, ceil(-1.1) v3, ceiling(1.9) v
> ---- --- --- ---- --- ----
> null 1.0 2.0 -1.0 2.0 -1.0
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,5 +14,3 @@ select cos(null) vn, cos(-1) r1 from test;
> ---- ------------------
> null 0.5403023058681398
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,5 +14,3 @@ select cot(null) vn, cot(-1) r1 from test;
> ---- -------------------
> null -0.6420926159343306
> rows: 1
......@@ -14,6 +14,3 @@ select exp(null) vn, left(exp(1), 4) v1, left(exp(1.1), 4) v2, left(exp(-1.1), 4
> ---- ---- ---- ---- ---- ----
> null 2.71 3.00 0.33 6.68 0.14
> rows: 1
......@@ -14,9 +14,3 @@ select floor(null) vn, floor(1) v1, floor(1.1) v2, floor(-1.1) v3, floor(1.9) v4
> ---- --- --- ---- --- ----
> null 1.0 1.0 -2.0 1.0 -2.0
> rows: 1
......@@ -38,8 +38,3 @@ select octet_length(null) en, octet_length('') e0, octet_length('ab') e4 from te
> ---- -- --
> null 0 4
> rows: 1
......@@ -26,9 +26,3 @@ select log(null) vn, log(1) v1, log(1.1) v2, log(-1.1) v3, log(1.9) v4, log(-1.9
> ---- --- ------------------- --- ------------------ ---
> null 0.0 0.09531017980432493 NaN 0.6418538861723947 NaN
> rows: 1
......@@ -14,7 +14,3 @@ select mod(null, 1) vn, mod(1, null) vn1, mod(null, null) vn2, mod(10, 2) e1 fro
> ---- ---- ---- --
> null null null 0
> rows: 1
......@@ -14,7 +14,3 @@ select power(null, null) en, power(2, 3) e8, power(16, 0.5) e4 from test;
> ---- --- ---
> null 8.0 4.0
> rows: 1
......@@ -26,6 +26,3 @@ select roundmagic(null) en, roundmagic(cast(3.11 as double) - 3.1) e001, roundma
> ---- ---- ---- ------
> null 0.01 0.0 2.0E12
> rows: 1
......@@ -14,5 +14,3 @@ select sin(null) vn, sin(-1) r1 from test;
> ---- -------------------
> null -0.8414709848078965
> rows: 1
......@@ -14,6 +14,3 @@ select sqrt(null) vn, sqrt(0) e0, sqrt(1) e1, sqrt(4) e2, sqrt(100) e10, sqrt(0.
> ---- --- --- --- ---- ---
> null 0.0 1.0 2.0 10.0 0.5
> rows: 1
......@@ -14,6 +14,3 @@ select tan(null) vn, tan(-1) r1 from test;
> ---- -------------------
> null -1.5574077246549023
> rows: 1
......@@ -14,7 +14,3 @@ select ascii(null) en, ascii('') en, ascii('Abc') e65 from test;
> ---- ---- ---
> null null 65
> rows: 1
......@@ -14,4 +14,3 @@ select hextoraw(null) en, rawtohex(null) en1, hextoraw(rawtohex('abc')) abc from
> ---- ---- ---
> null null abc
> rows: 1
......@@ -20,4 +20,3 @@ select insert('World', 2, 4, 'e') welt, insert('Hello', 2, 1, 'a') hallo from te
> ---- -----
> We Hallo
> rows: 1
......@@ -28,4 +28,4 @@ select len(null) en, len('MSSQLServer uses the len keyword') e_32 from test;
> rows: 1
SET MODE Regular;
> ok
\ No newline at end of file
> ok
......@@ -9,7 +9,6 @@ create memory table test(id int primary key, name varchar(255));
insert into test values(1, 'Hello');
> update count: 1
select cast(null as varchar(255)) xn, cast(' 10' as int) x10, cast(' 20 ' as int) x20 from test;
> XN X10 X20
> ---- --- ---
......
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -20,4 +20,3 @@ select isnull(null, '1') x1, isnull(null, null) xn, isnull('a', 'b') xa from tes
> -- ---- --
> 1 null a
> rows: 1
......@@ -15,7 +15,6 @@ select length(curtime())>=8 c1, length(current_time())>=8 c2, substring(curtime(
> TRUE TRUE :
> rows: 1
select length(now())>18 c1, length(current_timestamp())>18 c2, length(now(0))>18 c3, length(now(2))>18 c4 from test;
> C1 C2 C3 C4
> ---- ---- ---- ----
......
......@@ -25,4 +25,4 @@ SELECT CURRENT_DATE = GETDATE();
>> TRUE
SET MODE Regular;
> ok
\ No newline at end of file
> ok
......@@ -372,7 +372,6 @@ SELECT DATE_TRUNC('second', '2015-05-29 00:00:00');
SELECT DATE_TRUNC('SECOND', '2015-05-29 00:00:00');
>> 2015-05-29 00:00:00
--
-- Test time unit 'MINUTE'
--
......@@ -598,7 +597,6 @@ select DATE_TRUNC('day', '2015-05-29 15:14:13');
select DATE_TRUNC('DAY', '2015-05-29 15:14:13');
>> 2015-05-29 00:00:00
--
-- Test time unit 'WEEK'
--
......@@ -818,7 +816,6 @@ SELECT DATE_TRUNC('quarter', '2015-12-29 15:14:13');
SELECT DATE_TRUNC('QUARTER', '2015-12-29 15:14:13');
>> 2015-10-01 00:00:00
--
-- Test time unit 'YEAR'
--
......@@ -1073,4 +1070,3 @@ SELECT DATE_TRUNC('', '');
SELECT DATE_TRUNC('YEAR', '');
> exception INVALID_DATETIME_CONSTANT_2
......@@ -87,7 +87,6 @@ SELECT *,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) F_U_C,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) F_C_U,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) F_U_U,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID) L,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) L_U_C,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) L_C_U,
......
......@@ -22,13 +22,11 @@ SELECT *,
ROW_NUMBER() OVER () RN,
ROUND(PERCENT_RANK() OVER (), 2) PR,
ROUND(CUME_DIST() OVER (), 2) CD,
ROW_NUMBER() OVER (ORDER BY ID) RNO,
RANK() OVER (ORDER BY ID) RKO,
DENSE_RANK() OVER (ORDER BY ID) DRO,
ROUND(PERCENT_RANK() OVER (ORDER BY ID), 2) PRO,
ROUND(CUME_DIST() OVER (ORDER BY ID), 2) CDO
FROM TEST;
> ID CATEGORY VALUE RN PR CD RNO RKO DRO PRO CDO
> -- -------- ----- -- --- --- --- --- --- ---- ----
......
......@@ -744,33 +744,46 @@ DROP TABLE C;
CREATE TABLE T1(X1 INT);
> ok
CREATE TABLE T2(X2 INT);
> ok
CREATE TABLE T3(X3 INT);
> ok
CREATE TABLE T4(X4 INT);
> ok
CREATE TABLE T5(X5 INT);
> ok
INSERT INTO T1 VALUES (1);
> update count: 1
INSERT INTO T1 VALUES (NULL);
> update count: 1
INSERT INTO T2 VALUES (1);
> update count: 1
INSERT INTO T2 VALUES (NULL);
> update count: 1
INSERT INTO T3 VALUES (1);
> update count: 1
INSERT INTO T3 VALUES (NULL);
> update count: 1
INSERT INTO T4 VALUES (1);
> update count: 1
INSERT INTO T4 VALUES (NULL);
> update count: 1
INSERT INTO T5 VALUES (1);
> update count: 1
INSERT INTO T5 VALUES (NULL);
> update count: 1
......
......@@ -2523,6 +2523,7 @@ insert into address(id, name, name2) values(2, 'test@abc', 'test@acme');
> exception CHECK_CONSTRAINT_VIOLATED_1
@reconnect
insert into address(id, name, name2) values(3, 'test_abc', 'test@gmail');
> exception CHECK_CONSTRAINT_VIOLATED_1
......@@ -7954,4 +7955,3 @@ select * from test where year in (select distinct year from test order by year d
drop table test;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论