Improve coverage of psql for backslash commands with \if and \elif
authorMichael Paquier <michael@paquier.xyz>
Thu, 12 Sep 2019 01:35:13 +0000 (10:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 12 Sep 2019 01:35:13 +0000 (10:35 +0900)
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

src/test/regress/expected/psql.out
src/test/regress/sql/psql.sql

index ef534a36a06e204a52db0f0d400b7b74da121563..242f817163e73c6ef905a0d83a80c72914512cfd 100644 (file)
@@ -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
index 2e379849625b39f787d5e9680a126344c600d969..26a0bcf7181b3a723b936617811754f63394c6ce 100644 (file)
@@ -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