summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-09-12 10:35:13 +0900
committerMichael Paquier <michael@paquier.xyz>2019-09-12 10:35:13 +0900
commitaafe2762b152ffd4cb839d2a01df6cfcc3c6df6c (patch)
tree7101a5a88948b07ef54ce2f174b4f4a7457df4a8
parent9a86f03b4e8c8f16eca7faebcb4a46330e431102 (diff)
Improve coverage of psql for backslash commands with \if and \elif
This adds tests to cover more code paths to ignore backslash commands in false branches when using \if|\elif|\else, and improves the coverage of \elif. Author: Fabien Coelho Discussion: https://postgr.es/m/alpine.DEB.2.21.1908281618520.28828@lancre
-rw-r--r--src/test/regress/expected/psql.out63
-rw-r--r--src/test/regress/sql/psql.sql62
2 files changed, 111 insertions, 14 deletions
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index ef534a36a06..242f817163e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -4275,6 +4275,17 @@ all true
\echo 'all false'
all false
\endif
+-- test true-false elif after initial true branch
+\if true
+ \echo 'should print #2-5'
+should print #2-5
+\elif true
+ \echo 'should not print #2-6'
+\elif false
+ \echo 'should not print #2-7'
+\else
+ \echo 'should not print #2-8'
+\endif
-- test simple true-then-else
\if true
\echo 'first thing true'
@@ -4348,22 +4359,60 @@ bar 'bar' "bar"
:try_to_quit
\echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
- \a \C arg1 \c arg1 arg2 arg3 arg4 \cd arg1 \conninfo
+ \a
+ \C arg1
+ \c arg1 arg2 arg3 arg4
+ \cd arg1
+ \conninfo
\copy arg1 arg2 arg3 arg4 arg5 arg6
- \copyright \dt arg1 \e arg1 arg2
+ \copyright
+ SELECT 1 as one, 2, 3 \crosstabview
+ \dt arg1
+ \e arg1 arg2
\ef whole_line
\ev whole_line
- \echo arg1 arg2 arg3 arg4 arg5 \echo arg1 \encoding arg1 \errverbose
- \g arg1 \gx arg1 \gexec \h \html \i arg1 \ir arg1 \l arg1 \lo arg1 arg2
- \o arg1 \p \password arg1 \prompt arg1 arg2 \pset arg1 arg2 \q
- \reset \s arg1 \set arg1 arg2 arg3 arg4 arg5 arg6 arg7 \setenv arg1 arg2
+ \echo arg1 arg2 arg3 arg4 arg5
+ \echo arg1
+ \encoding arg1
+ \errverbose
+ \f arg1
+ \g arg1
+ \gx arg1
+ \gexec
+ SELECT 1 AS one \gset
+ \h
+ \?
+ \html
+ \i arg1
+ \ir arg1
+ \l arg1
+ \lo arg1 arg2
+invalid command \lo
+ \lo_list
+ \o arg1
+ \p
+ \password arg1
+ \prompt arg1 arg2
+ \pset arg1 arg2
+ \q
+ \reset
+ \s arg1
+ \set arg1 arg2 arg3 arg4 arg5 arg6 arg7
+ \setenv arg1 arg2
\sf whole_line
\sv whole_line
- \t arg1 \T arg1 \timing arg1 \unset arg1 \w arg1 \watch arg1 \x arg1
+ \t arg1
+ \T arg1
+ \timing arg1
+ \unset arg1
+ \w arg1
+ \watch arg1
+ \x arg1
-- \else here is eaten as part of OT_FILEPIPE argument
\w |/no/such/file \else
-- \endif here is eaten as part of whole-line argument
\! whole_line \endif
+ \z
\else
\echo 'should print #8-1'
should print #8-1
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 2e379849625..26a0bcf7181 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -843,6 +843,17 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
\echo 'all false'
\endif
+-- test true-false elif after initial true branch
+\if true
+ \echo 'should print #2-5'
+\elif true
+ \echo 'should not print #2-6'
+\elif false
+ \echo 'should not print #2-7'
+\else
+ \echo 'should not print #2-8'
+\endif
+
-- test simple true-then-else
\if true
\echo 'first thing true'
@@ -911,22 +922,59 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
:try_to_quit
\echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
- \a \C arg1 \c arg1 arg2 arg3 arg4 \cd arg1 \conninfo
+ \a
+ \C arg1
+ \c arg1 arg2 arg3 arg4
+ \cd arg1
+ \conninfo
\copy arg1 arg2 arg3 arg4 arg5 arg6
- \copyright \dt arg1 \e arg1 arg2
+ \copyright
+ SELECT 1 as one, 2, 3 \crosstabview
+ \dt arg1
+ \e arg1 arg2
\ef whole_line
\ev whole_line
- \echo arg1 arg2 arg3 arg4 arg5 \echo arg1 \encoding arg1 \errverbose
- \g arg1 \gx arg1 \gexec \h \html \i arg1 \ir arg1 \l arg1 \lo arg1 arg2
- \o arg1 \p \password arg1 \prompt arg1 arg2 \pset arg1 arg2 \q
- \reset \s arg1 \set arg1 arg2 arg3 arg4 arg5 arg6 arg7 \setenv arg1 arg2
+ \echo arg1 arg2 arg3 arg4 arg5
+ \echo arg1
+ \encoding arg1
+ \errverbose
+ \f arg1
+ \g arg1
+ \gx arg1
+ \gexec
+ SELECT 1 AS one \gset
+ \h
+ \?
+ \html
+ \i arg1
+ \ir arg1
+ \l arg1
+ \lo arg1 arg2
+ \lo_list
+ \o arg1
+ \p
+ \password arg1
+ \prompt arg1 arg2
+ \pset arg1 arg2
+ \q
+ \reset
+ \s arg1
+ \set arg1 arg2 arg3 arg4 arg5 arg6 arg7
+ \setenv arg1 arg2
\sf whole_line
\sv whole_line
- \t arg1 \T arg1 \timing arg1 \unset arg1 \w arg1 \watch arg1 \x arg1
+ \t arg1
+ \T arg1
+ \timing arg1
+ \unset arg1
+ \w arg1
+ \watch arg1
+ \x arg1
-- \else here is eaten as part of OT_FILEPIPE argument
\w |/no/such/file \else
-- \endif here is eaten as part of whole-line argument
\! whole_line \endif
+ \z
\else
\echo 'should print #8-1'
\endif