提交 b252eeac authored 作者: Noel Grandin's avatar Noel Grandin

start splitting up the test script file

上级 a189c7bd
......@@ -30,20 +30,21 @@ import org.h2.util.StringUtils;
*/
public class TestScript extends TestBase {
private static final String FILENAME = "org/h2/test/scripts/testScript.sql";
private static final String BASE_DIR = "org/h2/test/scripts/";
/** If set to true, the test will exit at the first failure. */
private boolean failFast;
private final ArrayList<String> statements = New.arrayList();
private boolean reconnectOften;
private Connection conn;
private Statement stat;
private LineNumberReader in;
private int line;
private int outputLineNo;
private PrintStream out;
private final ArrayList<String[]> result = New.arrayList();
private String putBack;
private StringBuilder errors;
private ArrayList<String> statements;
private Random random = new Random(1);
......@@ -64,8 +65,9 @@ public class TestScript extends TestBase {
*/
public ArrayList<String> getAllStatements(TestAll conf) throws Exception {
config = conf;
statements = New.arrayList();
if (statements.isEmpty()) {
test();
}
return statements;
}
......@@ -74,24 +76,34 @@ public class TestScript extends TestBase {
if (config.networked && config.big) {
return;
}
reconnectOften = false;
if (!config.memory) {
if (config.big) {
reconnectOften = true;
}
}
testScript();
reconnectOften = !config.memory && config.big;
testScript("testScript.sql");
testScript("functions-system-rownum.sql");
testScript("datatypes-enum.sql");
deleteDb("script");
System.out.flush();
}
private void testScript() throws Exception {
private void testScript(String scriptFileName) throws Exception {
deleteDb("script");
String outFile = "test.out.txt";
// Reset all the state in case there is anything left over from the previous file we processed.
conn = null;
stat = null;
in = null;
outputLineNo = 0;
out = null;
result.clear();
putBack = null;
errors = null;
println("Running commands in " + scriptFileName);
final String outFile = "test.out.txt";
conn = getConnection("script");
stat = conn.createStatement();
out = new PrintStream(new FileOutputStream(outFile));
errors = new StringBuilder();
testFile(FILENAME);
testFile(BASE_DIR + scriptFileName);
conn.close();
out.close();
if (errors.length() > 0) {
......@@ -172,9 +184,7 @@ public class TestScript extends TestBase {
}
}
}
if (statements != null) {
statements.add(sql);
}
if (sql.indexOf('?') == -1) {
processStatement(sql);
} else {
......@@ -358,7 +368,7 @@ public class TestScript extends TestBase {
return;
}
errors.append("line: ");
errors.append(line);
errors.append(outputLineNo);
errors.append("\n" + "exp: ");
errors.append(compare);
errors.append("\n" + "got: ");
......@@ -380,7 +390,7 @@ public class TestScript extends TestBase {
}
private void write(String s) {
line++;
outputLineNo++;
out.println(s);
}
......
----------------
--- ENUM support
----------------
--- ENUM basic operations
create table card (rank int, suit enum('hearts', 'clubs', 'spades'));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts');
> update count: 2
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
select * from card;
> RANK SUIT
> ---- ------
> 0 clubs
> 3 hearts
select * from card order by suit;
> RANK SUIT
> ---- ------
> 3 hearts
> 0 clubs
insert into card (rank, suit) values (8, 'diamonds'), (10, 'clubs'), (7, 'hearts');
> update count: 3
select suit, count(rank) from card group by suit order by suit, count(rank);
> SUIT COUNT(RANK)
> -------- -----------
> hearts 2
> clubs 2
> diamonds 1
select rank from card where suit = 'diamonds';
> RANK
> ----
> 8
--- ENUM integer-based operations
select rank from card where suit = 1;
> RANK
> ----
> 0
> 10
insert into card (rank, suit) values(5, 2);
> update count: 1
select * from card where rank = 5;
> RANK SUIT
> ---- ------
> 5 spades
--- ENUM edge cases
insert into card (rank, suit) values(6, ' ');
> exception
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', 'clubs');
> exception
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', '');
> exception
drop table card;
> ok
--- ENUM as custom user data type
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT);
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts');
> update count: 2
select * from card;
> RANK SUIT
> ---- ------
> 0 clubs
> 3 hearts
drop table card;
> ok
drop type CARD_SUIT;
> ok
--- ENUM in primary key with another column
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT, primary key(rank, suit));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (1, 'clubs');
> update count: 3
insert into card (rank, suit) values (0, 'clubs');
> exception
select rank from card where suit = 'clubs';
> RANK
> ----
> 0
> 1
drop table card;
> ok
drop type CARD_SUIT;
> ok
--- ENUM with index
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT, primary key(rank, suit));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (1, 'clubs');
> update count: 3
create index idx_card_suite on card(`suit`);
select rank from card where suit = 'clubs';
> RANK
> ----
> 0
> 1
select rank from card where suit in ('clubs');
> RANK
> ----
> 0
> 1
drop table card;
> ok
drop type CARD_SUIT;
> ok
----- Issue#600 -----
create table test as (select char(x) as str from system_range(48,90));
> ok
select row_number() over () as rnum, str from test where str = 'A';
> RNUM STR
> ---- ---
> 1 A
drop table test;
> ok
......@@ -10593,156 +10593,6 @@ create table z.z (id int);
drop schema z;
> ok
----------------
--- ENUM support
----------------
--- ENUM basic operations
create table card (rank int, suit enum('hearts', 'clubs', 'spades'));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts');
> update count: 2
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
select * from card;
> RANK SUIT
> ---- ------
> 0 clubs
> 3 hearts
select * from card order by suit;
> RANK SUIT
> ---- ------
> 3 hearts
> 0 clubs
insert into card (rank, suit) values (8, 'diamonds'), (10, 'clubs'), (7, 'hearts');
> update count: 3
select suit, count(rank) from card group by suit order by suit, count(rank);
> SUIT COUNT(RANK)
> -------- -----------
> hearts 2
> clubs 2
> diamonds 1
select rank from card where suit = 'diamonds';
> RANK
> ----
> 8
--- ENUM integer-based operations
select rank from card where suit = 1;
> RANK
> ----
> 0
> 10
insert into card (rank, suit) values(5, 2);
> update count: 1
select * from card where rank = 5;
> RANK SUIT
> ---- ------
> 5 spades
--- ENUM edge cases
insert into card (rank, suit) values(6, ' ');
> exception
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', 'clubs');
> exception
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', '');
> exception
drop table card;
> ok
--- ENUM as custom user data type
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT);
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts');
> update count: 2
select * from card;
> RANK SUIT
> ---- ------
> 0 clubs
> 3 hearts
drop table card;
> ok
drop type CARD_SUIT;
> ok
--- ENUM in primary key with another column
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT, primary key(rank, suit));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (1, 'clubs');
> update count: 3
insert into card (rank, suit) values (0, 'clubs');
> exception
select rank from card where suit = 'clubs';
> RANK
> ----
> 0
> 1
drop table card;
> ok
drop type CARD_SUIT;
> ok
--- ENUM with index
create type CARD_SUIT as enum('hearts', 'clubs', 'spades', 'diamonds');
> ok
create table card (rank int, suit CARD_SUIT, primary key(rank, suit));
> ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (1, 'clubs');
> update count: 3
create index idx_card_suite on card(`suit`);
select rank from card where suit = 'clubs';
> RANK
> ----
> 0
> 1
select rank from card where suit in ('clubs');
> RANK
> ----
> 0
> 1
drop table card;
> ok
drop type CARD_SUIT;
> ok
----- Issue#493 -----
create table test (year int, action varchar(10));
> ok
......@@ -10762,15 +10612,3 @@ select * from test where year in (select distinct year from test order by year d
drop table test;
> ok
----- Issue#600 -----
create table test as (select char(x) as str from system_range(48,90));
> ok
select row_number() over () as rnum, str from test where str = 'A';
> RNUM STR
> ---- ---
> 1 A
drop table test;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论