[PATCH] Add tests for psql tab completion
Hi hackers.
I'm attaching a patch that add some new test cases for tab completion of psql.
This is my first patch that I'm sending here so let me know if I'm doing something wrong.
--
Matheus Alcantara
Attachments:
0001-psql-Add-tests-for-tab-completion.patchtext/x-patch; name=0001-psql-Add-tests-for-tab-completion.patchDownload
From 6af6b972960f4e9017f1c311ee4b13a96d5f66a1 Mon Sep 17 00:00:00 2001
From: Matheus Alcantara <mths.dev@pm.me>
Date: Sat, 12 Feb 2022 16:45:55 -0300
Subject: [PATCH] psql: Add tests for tab completion
---
src/bin/psql/t/010_tab_completion.pl | 92 ++++++++++++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/src/bin/psql/t/010_tab_completion.pl b/src/bin/psql/t/010_tab_completion.pl
index 005961f34d..f74ff96226 100644
--- a/src/bin/psql/t/010_tab_completion.pl
+++ b/src/bin/psql/t/010_tab_completion.pl
@@ -45,6 +45,7 @@ $node->safe_psql('postgres',
. "CREATE TABLE mytab246 (f1 int, f2 text);\n"
. "CREATE TABLE \"mixedName\" (f1 int, f2 text);\n"
. "CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n"
+ . "CREATE INDEX idx_tab1_c1 ON tab1(c1);\n"
. "CREATE PUBLICATION some_publication;\n");
# Developers would not appreciate this test adding a bunch of junk to
@@ -382,6 +383,97 @@ check_completion(
clear_query();
+check_completion(
+ "CREATE OR REPLACE \t\t",
+ qr/AGGREGATE +LANGUAGE +RULE +TRIGGER +\r\nFUNCTION +PROCEDURE +TRANSFORM +VIEW/,
+ "check create or replace");
+
+clear_query();
+
+check_completion(
+ "ALTER FOREIGN \t\t",
+ qr/DATA WRAPPER +TABLE/ ,
+ "check alter foreign");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX \t\t",
+ qr/ALL IN TABLESPACE +information_schema. +tab1_pkey\r\nidx_tab1_c1/,
+ "check alter index");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 \t\t",
+ qr/ALTER COLUMN +NO DEPENDS ON EXTENSION +RESET\r\nATTACH PARTITION +OWNER TO +SET\r\nDEPENDS ON EXTENSION +RENAME TO/,
+ "check alter index <name>");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 ATTACH \t\t",
+ qr/PARTITION/,
+ "check alter index <name> attach");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 ATTACH PARTITION \t\t",
+ qr/idx_tab1_c1 +public. +\r\ninformation_schema. +tab1_pkey/,
+ "check alter index <name> ATTACH PARTITION");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 ALTER \t\t",
+ qr/COLUMN/,
+ "check alter index <name> alter");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 ALTER COLUMN \t\t",
+ qr/1 +SET +STATISTICS/,
+ "check alter index <name> alter column");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 ALTER COLUMN 1 SET \t\t",
+ qr/STATISTICS/,
+ "check alter index <name> alter column <column> set");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 SET \t\t",
+ qr/\( +TABLESPACE/,
+ "check alter index <name> set");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 RESET \t\t",
+ qr/\( +\a/,
+ "check alter index <name> reset");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 NO DEPENDS \t\t",
+ qr/ON EXTENSION/,
+ "check alter index <name> no depends");
+
+clear_query();
+
+check_completion(
+ "ALTER INDEX idx_tab1_c1 DEPENDS \t\t",
+ qr/ON EXTENSION/,
+ "check alter index <name> depends");
+
+clear_query();
+
# check VersionedQuery infrastructure
check_completion(
"DROP PUBLIC\t \t\t",
--
2.35.1
Matheus Alcantara <mths.dev@pm.me> writes:
I'm attaching a patch that add some new test cases for tab completion of psql.
What exactly is the motivation for these particular tests?
I believe that most of tab-complete.c is already covered, outside
of the giant if-else chain at the heart of psql_completion().
It's hard to summon interest in trying to cover every branch of
that chain; but if we're to add coverage of just a few more,
which ones and why? The ones you've chosen to hit in this
patch don't seem especially interesting.
regards, tom lane
[ Please keep the mailing list cc'd ]
Matheus Alcantara <mths.dev@pm.me> writes:
On Monday, February 14th, 2022 at 17:01, Tom Lane <tgl@sss.pgh.pa.us> wrote:
What exactly is the motivation for these particular tests?
I was studying the source code and looking for projects that I could contribute so I decided
to start with tests, so I ran coverage and started with files that had little coverage, realized
that psql tab completion ones had little coverage so I decided to add some tests, I tried to
start with the simplest.
I understand that the patch may not be as much of a need, I just wanted to try and help with something.
Do you think there would be other tests that should be done? I would like to try to contribute.
There's certainly lots of places that could use more test coverage.
But I think that making a meaningful difference in tab-complete.c
would require writing test cases to hit most of the if-else branches,
which doesn't seem very profitable either in terms of test-writing
effort or in terms of the cycles that'd be spent on running those
tests forevermore. We try to be thrifty about how much work is
done by check-world, because it's a real advantage for development
that that takes a small number of minutes and not hours. I'm not
really seeing that covering more of tab-complete would buy much.
As for areas that *do* need more coverage, the first one that
I come across in looking through the coverage report is GIST
index build: gistbuild.c is only showing 45% coverage, and
gistbuildbuffers.c a fat zero [1]https://coverage.postgresql.org/src/backend/access/gist/index.html. We've looked at that before [2]/messages/by-id/10261.1588705157@sss.pgh.pa.us
but not made much progress on developing an adequately cheap test
case. Maybe you could pick up where that thread left off? Or if that
doesn't seem interesting to you, there's lots of other possibilities.
I'd suggest getting some buy-in from this list on what to work on
before you start, though.
regards, tom lane
[1]: https://coverage.postgresql.org/src/backend/access/gist/index.html
Import Notes
Reply to msg id not found: d_urhkNm44odv8cuFV9T9BXXQEbLlPb5smujNZ6kXaxkwtOtlltHecv5tDMCfJ2XtbrnhWlHLt_9rLohGlDn0W-EB5-D781QVzI8LhhEIoU@pm.me