aboutsummaryrefslogtreecommitdiff
path: root/src/test/modules/test_json_parser/t/003_test_semantic.pl
blob: 7ba8b63467c821032c11c07b7ed747999186b56a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2021-2025, PostgreSQL Global Development Group

# Test the incremental JSON parser with semantic routines, and compare the
# output with the expected output.

use strict;
use warnings FATAL => 'all';

use PostgreSQL::Test::Utils;
use Test::More;
use FindBin;

use File::Temp qw(tempfile);

my $test_file = "$FindBin::RealBin/../tiny.json";
my $test_out = "$FindBin::RealBin/../tiny.out";

my @exes = (
	[ "test_json_parser_incremental", ],
	[ "test_json_parser_incremental", "-o", ],
	[ "test_json_parser_incremental_shlib", ],
	[ "test_json_parser_incremental_shlib", "-o", ]);

foreach my $exe (@exes)
{
	note "testing executable @$exe";

	my ($stdout, $stderr) = run_command([ @$exe, "-s", $test_file ]);

	is($stderr, "", "no error output");

	my $dir = PostgreSQL::Test::Utils::tempdir;
	my ($fh, $fname) = tempfile(DIR => $dir);

	print $fh $stdout, "\n";

	close($fh);

	my @diffopts = ("-u");
	push(@diffopts, "--strip-trailing-cr") if $windows_os;
	($stdout, $stderr) =
	  run_command([ "diff", @diffopts, $fname, $test_out ]);

	is($stdout, "", "no output diff");
	is($stderr, "", "no diff error");
}

done_testing();