Ordering or sorting tests

11 views
Skip to first unread message

Jens Troeger

unread,
Nov 2, 2024, 11:04:10 AM11/2/24
to pgTAP Users
Hello, 

I understand that individual tests BEGIN and ROLLBACK their transaction, and the test(s) happens within that transaction. With that in mind, ordering tests shouldn’t be necessary.

However, I’d like to test some schema related issues first before moving on the views and procedures and whatnot. The latter wouldn’t work without the former in place.

So, how can I ensure a certain order of tests? Are filenames sorted? What about multiple files across multiple folders?

Thank you!
Jens

Austin Ziegler

unread,
Nov 17, 2024, 2:00:43 PM11/17/24
to Jens Troeger, pgTAP Users
I don't believe that there is a way to do this without multiple runs. That is, you could have two directories, `test/schema/` and `test/integration/` and run them like:

```
% pg_prove -U postgres test/schema/*.sql
% pg_prove -U postgres test/integration/*.sql
```

--
You received this message because you are subscribed to the Google Groups "pgTAP Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pgtap-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pgtap-users/0ca1193b-f771-47fe-9334-a0418557d597n%40googlegroups.com.


--

David E. Wheeler

unread,
Nov 17, 2024, 2:21:52 PM11/17/24
to Jens Troeger, pgTAP Users
On Nov 2, 2024, at 11:04, Jens Troeger <jens.t...@gmail.com> wrote:

> So, how can I ensure a certain order of tests? Are filenames sorted? What about multiple files across multiple folders?

pg_prove relies on App::Prove, and I *believe* it sorts files by filename. You have to pass `--shuffle` to get them in random order.

Best,

David

kevin

unread,
Nov 21, 2024, 3:19:30 PM11/21/24
to pgtap...@googlegroups.com
If that doesn't work for you, just take matters into your own hands by
using a bash script.

for f in $path/*.sql
do
    pg_prove $opts $f
done

The "for" should order the files as long as you have a natural order to
the filenames, like 01_setup_tables.sql, 02_test_views.sql, etc. If the
"for" doesn't order like you want, I'm sure there are many ways to force
it. The first that comes to mind for me is:
    for f in `ls -1 $path/*.sql`

Have fun!
Kevin
Reply all
Reply to author
Forward
0 new messages