Commit aafe2762 authored by Michael Paquier's avatar Michael Paquier

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
parent 9a86f03b
...@@ -4275,6 +4275,17 @@ all true ...@@ -4275,6 +4275,17 @@ all true
\echo 'all false' \echo 'all false'
all false all false
\endif \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 -- test simple true-then-else
\if true \if true
\echo 'first thing true' \echo 'first thing true'
...@@ -4348,22 +4359,60 @@ bar 'bar' "bar" ...@@ -4348,22 +4359,60 @@ bar 'bar' "bar"
:try_to_quit :try_to_quit
\echo `nosuchcommand` :foo :'foo' :"foo" \echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `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 \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 \ef whole_line
\ev whole_line \ev whole_line
\echo arg1 arg2 arg3 arg4 arg5 \echo arg1 \encoding arg1 \errverbose \echo arg1 arg2 arg3 arg4 arg5
\g arg1 \gx arg1 \gexec \h \html \i arg1 \ir arg1 \l arg1 \lo arg1 arg2 \echo arg1
\o arg1 \p \password arg1 \prompt arg1 arg2 \pset arg1 arg2 \q \encoding arg1
\reset \s arg1 \set arg1 arg2 arg3 arg4 arg5 arg6 arg7 \setenv arg1 arg2 \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 \sf whole_line
\sv 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 -- \else here is eaten as part of OT_FILEPIPE argument
\w |/no/such/file \else \w |/no/such/file \else
-- \endif here is eaten as part of whole-line argument -- \endif here is eaten as part of whole-line argument
\! whole_line \endif \! whole_line \endif
\z
\else \else
\echo 'should print #8-1' \echo 'should print #8-1'
should print #8-1 should print #8-1
......
...@@ -843,6 +843,17 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two; ...@@ -843,6 +843,17 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
\echo 'all false' \echo 'all false'
\endif \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 -- test simple true-then-else
\if true \if true
\echo 'first thing true' \echo 'first thing true'
...@@ -911,22 +922,59 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two; ...@@ -911,22 +922,59 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
:try_to_quit :try_to_quit
\echo `nosuchcommand` :foo :'foo' :"foo" \echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `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 \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 \ef whole_line
\ev whole_line \ev whole_line
\echo arg1 arg2 arg3 arg4 arg5 \echo arg1 \encoding arg1 \errverbose \echo arg1 arg2 arg3 arg4 arg5
\g arg1 \gx arg1 \gexec \h \html \i arg1 \ir arg1 \l arg1 \lo arg1 arg2 \echo arg1
\o arg1 \p \password arg1 \prompt arg1 arg2 \pset arg1 arg2 \q \encoding arg1
\reset \s arg1 \set arg1 arg2 arg3 arg4 arg5 arg6 arg7 \setenv arg1 arg2 \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 \sf whole_line
\sv 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 -- \else here is eaten as part of OT_FILEPIPE argument
\w |/no/such/file \else \w |/no/such/file \else
-- \endif here is eaten as part of whole-line argument -- \endif here is eaten as part of whole-line argument
\! whole_line \endif \! whole_line \endif
\z
\else \else
\echo 'should print #8-1' \echo 'should print #8-1'
\endif \endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment