Skip to content

Commit 78c0a2c

Browse files
committed
feat: use postgres regress tests
1 parent ab3c4ea commit 78c0a2c

File tree

2 files changed

+250
-32
lines changed

2 files changed

+250
-32
lines changed

crates/parser/tests/skipped.txt

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
advisory_lock
2+
aggregates
3+
alter_generic
4+
alter_operator
5+
alter_table
6+
amutils
7+
arrays
8+
async
9+
bit
10+
bitmapops
11+
boolean
12+
box
13+
brin
14+
brin_bloom
15+
brin_multi
16+
btree_index
17+
case
18+
char
19+
circle
20+
cluster
21+
collate.icu.utf8
22+
collate.linux.utf8
23+
collate
24+
combocid
25+
comments
26+
compression
27+
constraints
28+
conversion
29+
copy
30+
copy2
31+
copydml
32+
copyselect
33+
create_aggregate
34+
create_am
35+
create_cast
36+
create_function_c
37+
create_function_sql
38+
create_index
39+
create_index_spgist
40+
create_misc
41+
create_operator
42+
create_procedure
43+
create_role
44+
create_table
45+
create_table_like
46+
create_type
47+
create_view
48+
date
49+
dbsize
50+
delete
51+
dependency
52+
domain
53+
drop_if_exists
54+
drop_operator
55+
enum
56+
equivclass
57+
errors
58+
event_trigger
59+
explain
60+
expressions
61+
fast_default
62+
float4
63+
float8
64+
foreign_data
65+
foreign_key
66+
functional_deps
67+
generated
68+
geometry
69+
gin
70+
gist
71+
groupingsets
72+
guc
73+
hash_func
74+
hash_index
75+
hash_part
76+
horology
77+
identity
78+
incremental_sort
79+
index_including
80+
index_including_gist
81+
indexing
82+
indirect_toast
83+
inet
84+
infinite_recurse
85+
inherit
86+
init_privs
87+
insert
88+
insert_conflict
89+
int2
90+
int4
91+
int8
92+
interval
93+
join
94+
join_hash
95+
json
96+
json_encoding
97+
jsonb
98+
jsonb_jsonpath
99+
jsonpath
100+
jsonpath_encoding
101+
largeobject
102+
limit
103+
line
104+
lock
105+
lseg
106+
macaddr
107+
macaddr8
108+
matview
109+
memoize
110+
merge
111+
misc
112+
misc_functions
113+
misc_sanity
114+
money
115+
multirangetypes
116+
mvcc
117+
name
118+
namespace
119+
numeric
120+
numeric_big
121+
numerology
122+
object_address
123+
oid
124+
oidjoins
125+
opr_sanity
126+
partition_aggregate
127+
partition_info
128+
partition_join
129+
partition_prune
130+
password
131+
path
132+
pg_lsn
133+
plancache
134+
plpgsql
135+
point
136+
polygon
137+
polymorphism
138+
portals
139+
portals_p2
140+
prepare
141+
prepared_xacts
142+
privileges
143+
psql
144+
psql_crosstab
145+
publication
146+
random
147+
rangefuncs
148+
rangetypes
149+
regex
150+
regproc
151+
reindex_catalog
152+
reloptions
153+
replica_identity
154+
returning
155+
roleattributes
156+
rowsecurity
157+
rowtypes
158+
rules
159+
sanity_check
160+
security_label
161+
select
162+
select_distinct
163+
select_distinct_on
164+
select_having
165+
select_implicit
166+
select_into
167+
select_parallel
168+
select_views
169+
sequence
170+
spgist
171+
stats
172+
stats_ext
173+
strings
174+
subscription
175+
subselect
176+
sysviews
177+
tablesample
178+
tablespace
179+
temp
180+
test_setup
181+
text
182+
tid
183+
tidrangescan
184+
tidscan
185+
time
186+
timestamp
187+
timestamptz
188+
timetz
189+
transactions
190+
triggers
191+
truncate
192+
tsdicts
193+
tsearch
194+
tsrf
195+
tstypes
196+
tuplesort
197+
txid
198+
type_sanity
199+
typed_table
200+
unicode
201+
union
202+
updatable_views
203+
update
204+
uuid
205+
vacuum
206+
vacuum_parallel
207+
varchar
208+
window
209+
with
210+
write_parallel
211+
xid
212+
xml
213+
xmlmap

crates/parser/tests/statement_parser_test.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,56 @@ use pg_query::split_with_parser;
77
use std::{fs, panic};
88

99
const VALID_STATEMENTS_PATH: &str = "tests/data/statements/valid/";
10+
const POSTGRES_REGRESS_PATH: &str = "../../libpg_query/test/sql/postgres_regress/";
11+
const SKIPPED_REGRESS_TESTS: &str = include_str!("skipped.txt");
1012

1113
#[test]
1214
fn valid_statements() {
1315
common::setup();
1416

15-
let mut paths: Vec<_> = fs::read_dir(VALID_STATEMENTS_PATH)
16-
.unwrap()
17-
.map(|r| r.unwrap())
18-
.collect();
19-
paths.sort_by_key(|dir| dir.path());
17+
for path in [VALID_STATEMENTS_PATH, POSTGRES_REGRESS_PATH] {
18+
let mut paths: Vec<_> = fs::read_dir(path).unwrap().map(|r| r.unwrap()).collect();
19+
paths.sort_by_key(|dir| dir.path());
2020

21-
for f in paths.iter() {
22-
let path = f.path();
23-
let test_name = path.file_stem().unwrap().to_str().unwrap();
21+
for f in paths.iter() {
22+
let path = f.path();
23+
let test_name = path.file_stem().unwrap().to_str().unwrap();
2424

25-
let contents = fs::read_to_string(&path).unwrap();
26-
let cases = split_with_parser(&contents).unwrap();
25+
if SKIPPED_REGRESS_TESTS.contains(&test_name) {
26+
continue;
27+
}
2728

28-
for (i, case) in cases.iter().enumerate() {
29-
let case = format!("{};", case.trim());
29+
let contents = fs::read_to_string(&path).unwrap();
30+
let cases = split_with_parser(&contents).unwrap();
3031

31-
debug!("Parsing statement {}\n{}", test_name, case);
32+
for (i, case) in cases.iter().enumerate() {
33+
let case = format!("{};", case.trim());
3234

33-
let result = panic::catch_unwind(|| parse_source(&case));
35+
debug!("Parsing statement {}\n{}", test_name, case);
3436

35-
if result.is_err() {
36-
assert!(false, "Failed to parse statement {}:\n{}", test_name, case);
37-
} else {
38-
info!(
39-
"Successfully parsed statement {}\n'{}'\n{:#?}",
40-
test_name,
41-
case,
42-
result.as_ref().unwrap().cst
43-
);
44-
}
37+
let result = panic::catch_unwind(|| parse_source(&case));
4538

46-
let mut settings = Settings::clone_current();
47-
settings.set_input_file(&path);
48-
settings.set_prepend_module_to_snapshot(false);
49-
settings.set_description(case.to_string());
50-
settings.set_omit_expression(true);
51-
settings.set_snapshot_path("snapshots/statements/valid");
52-
settings.set_snapshot_suffix((i + 1).to_string());
39+
if result.is_err() {
40+
assert!(false, "Failed to parse statement {}:\n{}", test_name, case);
41+
} else {
42+
info!(
43+
"Successfully parsed statement {}\n'{}'\n{:#?}",
44+
test_name,
45+
case,
46+
result.as_ref().unwrap().cst
47+
);
48+
}
5349

54-
settings.bind(|| assert_debug_snapshot!(test_name, result.unwrap()));
50+
let mut settings = Settings::clone_current();
51+
settings.set_input_file(&path);
52+
settings.set_prepend_module_to_snapshot(false);
53+
settings.set_description(case.to_string());
54+
settings.set_omit_expression(true);
55+
settings.set_snapshot_path("snapshots/statements/valid");
56+
settings.set_snapshot_suffix((i + 1).to_string());
57+
58+
settings.bind(|| assert_debug_snapshot!(test_name, result.unwrap()));
59+
}
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)