From d4c3b35dffc2c46898c884fa8c9fe1c8eb434ad4 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Tue, 17 Mar 2026 10:01:13 +0100
Subject: [PATCH v5 5/5] Simplify and improve output of 002_pg_upgrade.pl and
 027_stream_regress.pl tests

Due to recent commits test output of both pg_regress and command_ok have
been improved. This allows us to simplify the way pg_regress was run
in both the 002_pg_upgrade.pl and 027_stream_regress.pl, while at the
same time getting better output too.

The original output when running the test using meson looked like this
for 002_pg_upgrade.pl and for :

  stderr:
  #   Failed test 'regression tests pass'
  #   at /home/jelte/work/postgres-4/src/bin/pg_upgrade/t/002_pg_upgrade.pl line 308.
  #          got: '256'
  #     expected: '0'
  # Looks like you failed 1 test of 20.

  (test program exited with status code 1)

Now it contains something like:

> # -------------- stderr --------------
> # # diff -U3
> /home/jelte/work/postgres/src/test/regress/expected/stats_import.out
> /home/jelte/work/postgres/build/testrun/recovery/027_stream_regress/data/results/stats_import.out
> # # --- /home/jelte/work/postgres/src/test/regress/expected/stats_import.out
> 2026-03-19 15:20:35.413217825 -0400
> # # +++
> /home/jelte/work/postgres/build/testrun/recovery/027_stream_regress/data/results/stats_import.out
> 2026-03-19 15:20:57.565988863 -0400
> # # @@ -25,8 +25,6 @@
> # #      31
> # #  (1 row)
> # #
> # # --- OBVIOUS ERROR IS OBVIOUS
> # # -
> # #  -- Create a view that is used purely for the type based on
> pg_statistic.
> # #  CREATE VIEW stats_import.pg_statistic_flat_t AS
> # #    SELECT
> # # 1 of 243 tests failed.
> # # The differences that caused some tests to fail can be viewed in the
> file
> "/home/jelte/work/postgres/build/testrun/recovery/027_stream_regress/data/regression.diffs".
> # # A copy of the test summary that you see above is saved in the file
> "/home/jelte/work/postgres/build/testrun/recovery/027_stream_regress/data/regression.out".
> # ------------------------------------

For 027_stream_regress.pl it would already dump the head and tail of the
diff, but with a long diff the head of the diff would be outside of the
100 line limit that meson output imposes. With the new output we can
actually see the first failure, which is most often what we want to see.
And the output is no shown in a consistent way with other tests.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/DFYFWM053WHS.10K8ZPJ605UFK@jeltef.nl
---
 src/bin/pg_upgrade/t/002_pg_upgrade.pl    | 40 ++++++-----------
 src/test/recovery/t/027_stream_regress.pl | 55 +++++++----------------
 2 files changed, 29 insertions(+), 66 deletions(-)

diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index cd2d2f30078..0a4121fdc4d 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -280,32 +280,20 @@ else
 	# --inputdir points to the path of the input files.
 	my $inputdir = "$srcdir/src/test/regress";
 
-	note 'running regression tests in old instance';
-	my $rc =
-	  system($ENV{PG_REGRESS}
-		  . " $extra_opts "
-		  . "--dlpath=\"$dlpath\" "
-		  . "--bindir= "
-		  . "--host="
-		  . $oldnode->host . " "
-		  . "--port="
-		  . $oldnode->port . " "
-		  . "--schedule=$srcdir/src/test/regress/parallel_schedule "
-		  . "--max-concurrent-tests=20 "
-		  . "--inputdir=\"$inputdir\" "
-		  . "--outputdir=\"$outputdir\"");
-	if ($rc != 0)
-	{
-		# Dump out the regression diffs file, if there is one
-		my $diffs = "$outputdir/regression.diffs";
-		if (-e $diffs)
-		{
-			print "=== dumping $diffs ===\n";
-			print slurp_file($diffs);
-			print "=== EOF ===\n";
-		}
-	}
-	is($rc, 0, 'regression tests pass');
+	command_ok(
+		[
+			$ENV{PG_REGRESS},
+			split(' ', $extra_opts),
+			"--dlpath=$dlpath",
+			'--bindir=',
+			'--host=' . $oldnode->host,
+			'--port=' . $oldnode->port,
+			"--schedule=$srcdir/src/test/regress/parallel_schedule",
+			'--max-concurrent-tests=20',
+			"--inputdir=$inputdir",
+			"--outputdir=$outputdir"
+		],
+		'regression tests in old instance');
 }
 
 # Initialize a new node for the upgrade.
diff --git a/src/test/recovery/t/027_stream_regress.pl b/src/test/recovery/t/027_stream_regress.pl
index 259fd680ff3..ae977297849 100644
--- a/src/test/recovery/t/027_stream_regress.pl
+++ b/src/test/recovery/t/027_stream_regress.pl
@@ -68,48 +68,23 @@ my $outputdir = $PostgreSQL::Test::Utils::tmp_check;
 
 # Run the regression tests against the primary.
 my $extra_opts = $ENV{EXTRA_REGRESS_OPTS} || "";
-my $rc =
-  system($ENV{PG_REGRESS}
-	  . " $extra_opts "
-	  . "--dlpath=\"$dlpath\" "
-	  . "--bindir= "
-	  . "--host="
-	  . $node_primary->host . " "
-	  . "--port="
-	  . $node_primary->port . " "
-	  . "--schedule=../regress/parallel_schedule "
-	  . "--max-concurrent-tests=20 "
-	  . "--inputdir=../regress "
-	  . "--outputdir=\"$outputdir\"");
-
-# Regression diffs are only meaningful if both the primary and the standby
-# are still alive after a regression test failure.
+command_ok(
+	[
+		$ENV{PG_REGRESS},
+		split(' ', $extra_opts),
+		"--dlpath=$dlpath",
+		'--bindir=',
+		'--host=' . $node_primary->host,
+		'--port=' . $node_primary->port,
+		'--schedule=../regress/parallel_schedule',
+		'--max-concurrent-tests=20',
+		'--inputdir=../regress',
+		"--outputdir=$outputdir"
+	],
+	'regression tests pass');
+
 my $primary_alive = $node_primary->is_alive;
 my $standby_alive = $node_standby_1->is_alive;
-if ($rc != 0 && $primary_alive && $standby_alive)
-{
-	# Dump out the regression diffs file, if there is one
-	my $diffs = "$outputdir/regression.diffs";
-	if (-e $diffs)
-	{
-		# Dump portions of the diff file.
-		my ($head, $tail) = read_head_tail($diffs);
-
-		diag("=== dumping $diffs (head) ===");
-		foreach my $line (@$head)
-		{
-			diag($line);
-		}
-
-		diag("=== dumping $diffs (tail) ===");
-		foreach my $line (@$tail)
-		{
-			diag($line);
-		}
-		diag("=== EOF ===");
-	}
-}
-is($rc, 0, 'regression tests pass');
 is($primary_alive, 1, 'primary alive after regression test run');
 is($standby_alive, 1, 'standby alive after regression test run');
 
-- 
2.53.0

