Skip to content

Commit 661b1c9

Browse files
committed
tests: Add newline handling to slt when multiline is not specified
Newlines are represented as a ⏎ character in the result specification.
1 parent 42bbc90 commit 661b1c9

File tree

4 files changed

+101
-24
lines changed

4 files changed

+101
-24
lines changed

src/sqllogictest/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl std::fmt::Display for Output {
101101
pub struct QueryOutput<'a> {
102102
pub types: Vec<Type>,
103103
pub sort: Sort,
104+
pub multiline: bool,
104105
pub label: Option<&'a str>,
105106
pub column_names: Option<Vec<mz_repr::ColumnName>>,
106107
pub mode: Mode,

src/sqllogictest/src/parser.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -300,30 +300,47 @@ impl<'a> Parser<'a> {
300300
Output::Values(vec![])
301301
} else {
302302
let mut vals: Vec<String> = output_str.lines().map(|s| s.to_owned()).collect();
303-
if let Mode::Cockroach = self.mode {
304-
let mut rows: Vec<Vec<String>> = vec![];
305-
for line in vals {
306-
let cols = split_cols(&line, types.len());
307-
if sort != Sort::No && cols.len() != types.len() {
308-
// We can't check this condition for
309-
// Sort::No, because some tests use strings
310-
// with whitespace that look like extra
311-
// columns. (Note that these tests never
312-
// use any of the sorting options.)
313-
bail!(
314-
"col len ({}) did not match declared col len ({})",
315-
cols.len(),
316-
types.len()
317-
);
303+
match self.mode {
304+
Mode::Standard => {
305+
if !multiline {
306+
vals = vals.into_iter().map(|val| val.replace('⏎', "\n")).collect();
318307
}
319-
rows.push(cols.into_iter().map(|col| col.replace('␠', " ")).collect());
320-
}
321-
if sort == Sort::Row {
322-
rows.sort();
323308
}
324-
vals = rows.into_iter().flatten().collect();
325-
if sort == Sort::Value {
326-
vals.sort();
309+
Mode::Cockroach => {
310+
let mut rows: Vec<Vec<String>> = vec![];
311+
for line in vals {
312+
let cols = split_cols(&line, types.len());
313+
if sort != Sort::No && cols.len() != types.len() {
314+
// We can't check this condition for
315+
// Sort::No, because some tests use strings
316+
// with whitespace that look like extra
317+
// columns. (Note that these tests never
318+
// use any of the sorting options.)
319+
bail!(
320+
"col len ({}) did not match declared col len ({})",
321+
cols.len(),
322+
types.len()
323+
);
324+
}
325+
rows.push(
326+
cols.into_iter()
327+
.map(|col| {
328+
let mut col = col.replace('␠', " ");
329+
if !multiline {
330+
col = col.replace('⏎', "\n");
331+
}
332+
col
333+
})
334+
.collect(),
335+
);
336+
}
337+
if sort == Sort::Row {
338+
rows.sort();
339+
}
340+
vals = rows.into_iter().flatten().collect();
341+
if sort == Sort::Value {
342+
vals.sort();
343+
}
327344
}
328345
}
329346
Output::Values(vals)
@@ -335,6 +352,7 @@ impl<'a> Parser<'a> {
335352
output: Ok(QueryOutput {
336353
types,
337354
sort,
355+
multiline,
338356
label,
339357
column_names,
340358
mode: self.mode,

src/sqllogictest/src/runner.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20012001
types: &Vec<Type>,
20022002
column_names: Option<&Vec<ColumnName>>,
20032003
actual_output: &Vec<String>,
2004+
multiline: bool,
20042005
) {
20052006
buf.append_header(input, expected_output, column_names);
20062007

@@ -2016,7 +2017,17 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20162017
if row.len() <= 1 {
20172018
buf.append(&row.iter().join(" "));
20182019
} else {
2019-
buf.append(&row.iter().map(|col| col.replace(' ', "␠")).join(" "));
2020+
buf.append(
2021+
&row.iter()
2022+
.map(|col| {
2023+
let mut col = col.replace(' ', "␠");
2024+
if !multiline {
2025+
col = col.replace('\n', "⏎");
2026+
}
2027+
col
2028+
})
2029+
.join(" "),
2030+
);
20202031
}
20212032
}
20222033
// In standard mode, output each value on its own line,
@@ -2026,7 +2037,11 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20262037
if i != 0 || j != 0 {
20272038
buf.append("\n");
20282039
}
2029-
buf.append(col);
2040+
buf.append(&if multiline {
2041+
col.clone()
2042+
} else {
2043+
col.replace('\n', "⏎")
2044+
});
20302045
}
20312046
}
20322047
}
@@ -2048,6 +2063,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20482063
output_str: expected_output,
20492064
types,
20502065
column_names,
2066+
multiline,
20512067
..
20522068
}),
20532069
..
@@ -2065,6 +2081,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20652081
types,
20662082
column_names.as_ref(),
20672083
actual_output,
2084+
*multiline,
20682085
);
20692086
}
20702087
(
@@ -2075,6 +2092,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20752092
output: Output::Values(_),
20762093
output_str: expected_output,
20772094
types,
2095+
multiline,
20782096
..
20792097
}),
20802098
..
@@ -2093,6 +2111,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20932111
types,
20942112
Some(actual_column_names),
20952113
actual_output,
2114+
*multiline,
20962115
);
20972116
}
20982117
(

test/sqllogictest/slt.slt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,42 @@ column␠name␠with␠spaces! nospaces space␠again
3838
1
3939
2
4040
3
41+
42+
mode standard
43+
44+
query TT
45+
SELECT 'result' || chr(10) || 'with' || chr(10) || 'newline', 'no newline in this one, but there are spaces'
46+
UNION
47+
SELECT 'one' || chr(10) || 'more' || chr(10) || 'row (with spaces)', 'easy'
48+
----
49+
one⏎more⏎row (with spaces)
50+
easy
51+
result⏎with⏎newline
52+
no newline in this one, but there are spaces
53+
54+
query T multiline
55+
SELECT 'result' || chr(10) || 'with' || chr(10) || 'newline';
56+
----
57+
result
58+
with
59+
newline
60+
EOF
61+
62+
mode cockroach
63+
64+
query TT
65+
SELECT 'result' || chr(10) || 'with' || chr(10) || 'newline', 'no newline in this one, but there are spaces'
66+
UNION
67+
SELECT 'one' || chr(10) || 'more' || chr(10) || 'row (with spaces)', 'easy'
68+
----
69+
one⏎more⏎row␠(with␠spaces) easy
70+
result⏎with⏎newline no␠newline␠in␠this␠one,␠but␠there␠are␠spaces
71+
72+
query T multiline
73+
SELECT 'result' || chr(10) || 'with' || chr(10) || 'newline';
74+
----
75+
result
76+
with
77+
newline
78+
EOF
79+

0 commit comments

Comments
 (0)