From 9ba39f10f521830cd776e3720f475f38fae3baae Mon Sep 17 00:00:00 2001
From: coreyhuinker <corey.huinker@gmail.com>
Date: Wed, 21 Dec 2022 00:28:12 -0500
Subject: [PATCH 2/2] Add regression tests for the setting of SHELL_EXIT_CODE
 within psql.

---
 src/test/regress/expected/psql.out | 11 +++++++++++
 src/test/regress/sql/psql.sql      |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 8fc62cebd2..29a5ae6ed9 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -1306,6 +1306,17 @@ execute q;
 +----+-------------+
 
 deallocate q;
+-- test SHELL_EXIT_CODE
+\! nosuchcommand
+sh: line 1: nosuchcommand: command not found
+\echo :SHELL_EXIT_CODE
+127
+\set nosuchvar `nosuchcommand`
+sh: line 1: nosuchcommand: command not found
+\! nosuchcommand
+sh: line 1: nosuchcommand: command not found
+\echo :SHELL_EXIT_CODE
+127
 -- test single-line header and data
 prepare q as select repeat('x',2*n) as "0123456789abcdef", repeat('y',20-2*n) as "0123456789" from generate_series(1,10) as n;
 \pset linestyle ascii
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 2da9665a19..623e7a0538 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -291,6 +291,13 @@ execute q;
 
 deallocate q;
 
+-- test SHELL_EXIT_CODE
+\! nosuchcommand
+\echo :SHELL_EXIT_CODE
+\set nosuchvar `nosuchcommand`
+\! nosuchcommand
+\echo :SHELL_EXIT_CODE
+
 -- test single-line header and data
 prepare q as select repeat('x',2*n) as "0123456789abcdef", repeat('y',20-2*n) as "0123456789" from generate_series(1,10) as n;
 
-- 
2.38.1

