Skip to content

Commit ff8b37b

Browse files
committed
Add more regression tests for pg_ls_dir()
This system function was being triggered once in the main regression test suite to check its SRF configuration, and more in other test modules but nothing checked the behavior of the options missing_ok and include_dot_dirs. This commit adds some tests for both options, to avoid mistakes if this code is manipulated in the future. Extracted from a larger patch by the same author, with a few tweaks by me. Author: Justin Pryzby Discussion: https://postgr.es/m/[email protected]
1 parent c6f2f01 commit ff8b37b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/test/regress/expected/misc_functions.out

+23
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,29 @@ select * from (select pg_ls_dir('.') a) a where a = 'base' limit 1;
378378
base
379379
(1 row)
380380

381+
-- Test missing_ok (second argument)
382+
select pg_ls_dir('does not exist', false, false); -- error
383+
ERROR: could not open directory "does not exist": No such file or directory
384+
select pg_ls_dir('does not exist', true, false); -- ok
385+
pg_ls_dir
386+
-----------
387+
(0 rows)
388+
389+
-- Test include_dot_dirs (third argument)
390+
select count(*) = 1 as dot_found
391+
from pg_ls_dir('.', false, true) as ls where ls = '.';
392+
dot_found
393+
-----------
394+
t
395+
(1 row)
396+
397+
select count(*) = 1 as dot_found
398+
from pg_ls_dir('.', false, false) as ls where ls = '.';
399+
dot_found
400+
-----------
401+
f
402+
(1 row)
403+
381404
select * from (select (pg_timezone_names()).name) ptn where name='UTC' limit 1;
382405
name
383406
------

src/test/regress/sql/misc_functions.sql

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1;
124124
select count(*) >= 0 as ok from pg_ls_archive_statusdir();
125125

126126
select * from (select pg_ls_dir('.') a) a where a = 'base' limit 1;
127+
-- Test missing_ok (second argument)
128+
select pg_ls_dir('does not exist', false, false); -- error
129+
select pg_ls_dir('does not exist', true, false); -- ok
130+
-- Test include_dot_dirs (third argument)
131+
select count(*) = 1 as dot_found
132+
from pg_ls_dir('.', false, true) as ls where ls = '.';
133+
select count(*) = 1 as dot_found
134+
from pg_ls_dir('.', false, false) as ls where ls = '.';
127135

128136
select * from (select (pg_timezone_names()).name) ptn where name='UTC' limit 1;
129137

0 commit comments

Comments
 (0)