Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1692080

Browse files
committed
Refactor TAP test code for file comparisons into new routine in Utils.pm
This unifies the output used should any differences be found in thefiles provided, information that 027_stream_regress did not show onfailures. TAP tests of pg_combinebackup and pg_upgrade now rely on therefactored routine, reducing the dependency to the diff command. Thecallers of this routine can optionally specify a custom line-comparisonfunction.There are a couple of tests that still use directly a diff command:001_pg_bsd_indent, 017_shm and test_json_parser's 003. These rely ondifferent properties and are left out for now.Extracted from a larger patch by the same author.Author: Ashutosh BapatDiscussion:https://postgr.es/m/Z6RQS-tMzGYjlA-H@paquier.xyz
1 parentecb8226 commit1692080

File tree

4 files changed

+53
-43
lines changed

4 files changed

+53
-43
lines changed

‎src/bin/pg_combinebackup/t/002_compare_backups.pl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,12 @@
192192

193193
# Compare the two dumps, there should be no differences other than
194194
# the tablespace paths.
195-
my$compare_res = compare_text(
195+
compare_files(
196196
$dump1,$dump2,
197+
"contents of dumps match for both PITRs",
197198
sub {
198199
s{create tablespace .* location .*\btspitr\K[12]}{N}ifor@_;
199200
return$_[0]ne$_[1];
200201
});
201-
note($dump1);
202-
note($dump2);
203-
is($compare_res, 0,"dumps are identical");
204-
205-
# Provide more context if the dumps do not match.
206-
if ($compare_res != 0)
207-
{
208-
my ($stdout,$stderr) =
209-
run_command(['diff','-u',$dump1,$dump2 ]);
210-
print"=== diff of$dump1 and$dump2\n";
211-
print"=== stdout ===\n";
212-
print$stdout;
213-
print"=== stderr ===\n";
214-
print$stderr;
215-
print"=== EOF ===\n";
216-
}
217202

218203
done_testing();

‎src/bin/pg_upgrade/t/002_pg_upgrade.pl

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
use Cwdqw(abs_path);
88
use File::Basenameqw(dirname);
9-
use File::Compare;
10-
use File::Findqw(find);
11-
use File::Pathqw(rmtree);
9+
use File::Findqw(find);
10+
use File::Pathqw(rmtree);
1211

1312
use PostgreSQL::Test::Cluster;
1413
use PostgreSQL::Test::Utils;
@@ -515,20 +514,7 @@ sub filter_dump
515514
my$dump2_filtered = filter_dump(0,$oldnode->pg_version,$dump2_file);
516515

517516
# Compare the two dumps, there should be no differences.
518-
my$compare_res = compare($dump1_filtered,$dump2_filtered);
519-
is($compare_res, 0,'old and new dumps match after pg_upgrade');
520-
521-
# Provide more context if the dumps do not match.
522-
if ($compare_res != 0)
523-
{
524-
my ($stdout,$stderr) =
525-
run_command(['diff','-u',$dump1_filtered,$dump2_filtered ]);
526-
print"=== diff of$dump1_filtered and$dump2_filtered\n";
527-
print"=== stdout ===\n";
528-
print$stdout;
529-
print"=== stderr ===\n";
530-
print$stderr;
531-
print"=== EOF ===\n";
532-
}
517+
compare_files($dump1_filtered,$dump2_filtered,
518+
'old and new dumps match after pg_upgrade');
533519

534520
done_testing();

‎src/test/perl/PostgreSQL/Test/Utils.pm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use Cwd;
5050
use Exporter'import';
5151
use Fcntlqw(:mode :seek);
5252
use File::Basename;
53+
use File::Compare;
5354
use File::Find;
5455
use File::Spec;
5556
use File::statqw(stat);
@@ -70,6 +71,7 @@ our @EXPORT = qw(
7071
check_mode_recursive
7172
chmod_recursive
7273
check_pg_config
74+
compare_files
7375
dir_symlink
7476
scan_server_header
7577
system_or_bail
@@ -773,6 +775,45 @@ sub check_pg_config
773775

774776
=pod
775777
778+
=itemcompare_files(file1, file2, testname)
779+
780+
Check that two files match, printing the difference if any.
781+
782+
C<line_comp_function> is an optional CODE reference to a line comparison
783+
function, passed down as-is to File::Compare::compare_text.
784+
785+
=cut
786+
787+
subcompare_files
788+
{
789+
my ($file1,$file2,$testname,$line_comp_function) =@_;
790+
791+
# If nothing is given, all lines should be equal.
792+
$line_comp_function =sub {$_[0]ne$_[1] }
793+
unlessdefined$line_comp_function;
794+
795+
my$compare_res =
796+
File::Compare::compare_text($file1,$file2,$line_comp_function);
797+
is($compare_res, 0,$testname);
798+
799+
# Provide more context if the files do not match.
800+
if ($compare_res != 0)
801+
{
802+
my ($stdout,$stderr) =
803+
run_command(['diff','-u',$file1,$file2 ]);
804+
print"=== diff of$file1 and$file2\n";
805+
print"=== stdout ===\n";
806+
print$stdout;
807+
print"=== stderr ===\n";
808+
print$stderr;
809+
print"=== EOF ===\n";
810+
}
811+
812+
return;
813+
}
814+
815+
=pod
816+
776817
=itemdir_symlink(oldname, newname)
777818
778819
Portably create a symlink for a directory. On Windows this creates a junction

‎src/test/recovery/t/027_stream_regress.pl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@
120120
'--port'=>$node_standby_1->port,
121121
],
122122
'dump standby server');
123-
command_ok(
124-
['diff',$outputdir .'/primary.dump',$outputdir .'/standby.dump', ],
123+
compare_files(
124+
$outputdir .'/primary.dump',
125+
$outputdir .'/standby.dump',
125126
'compare primary and standby dumps');
126127

127128
# Likewise for the catalogs of the regression database, after disabling
@@ -150,12 +151,9 @@
150151
'regression',
151152
],
152153
'dump catalogs of standby server');
153-
command_ok(
154-
[
155-
'diff',
156-
$outputdir .'/catalogs_primary.dump',
157-
$outputdir .'/catalogs_standby.dump',
158-
],
154+
compare_files(
155+
$outputdir .'/catalogs_primary.dump',
156+
$outputdir .'/catalogs_standby.dump',
159157
'compare primary and standby catalog dumps');
160158

161159
# Check some data from pg_stat_statements.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp