Skip to content

Commit c9a18cd

Browse files
committed
more test cases for tail-log-to-ndjson
1 parent 8ea2af5 commit c9a18cd

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

t/tail-log-to-ndjson.t

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,40 @@ my @cmd = (
5858
);
5959

6060
{
61-
open my $ofh, '>', $logtxt;
62-
print $ofh <<'EOF';
61+
{
62+
open my $ofh, '>', $logtxt;
63+
print $ofh <<'EOF';
6364
The last 1000 reports as of 2025-10-18T08:00:04Z:
6465
[2025-10-18T07:59:49Z] [Carlos Guevara] [pass] [JKEENAN/IPC-System-Simple-1.30.tar.gz] [i86pc-solaris-thread-multi-64] [perl-v5.43.4] [6bad3778-abf8-11f0-8c1e-b80f595f57ba] [2025-10-18T07:59:49Z]
6566
[2025-10-18T07:59:43Z] [Carlos Guevara] [unknown] [JDHEDDEN/threads-2.21.tar.gz] [amd64-netbsd-thread-multi] [perl-v5.43.4] [67e088d4-abf8-11f0-97a1-bb460411313d] [2025-10-18T07:59:43Z]
6667
[2025-10-18T07:54:07Z] [Chris Williams (BINGOS)] [pass] [/] [x86_64-linux] [perl-v5.18.2] [a018b394-abf7-11f0-a3bc-a055f9c4ba34] [2025-10-18T07:54:07Z]
6768
[2025-10-18T07:40:24Z] [Carlos Guevara] [pass] [ARISTOTLE/Text-Tabs+Wrap-2024.001.tar.gz] [i86pc-solaris-thread-multi-64] [perl-v5.43.4] [b50809d2-abf5-11f0-ab63-d1797d8a4f3d] [2025-10-18T07:40:24Z]
69+
[2025-10-18T07:29:02Z] [Carlos Guevara] [pass] [TINITA/Test-YAML-1.07.tar.gz] [amd64-netbsd-thread-multi] [perl-v5.43.4] [1e9545e2-abf4-11f0-8398-beaf3347c81e] [2025-10-18T07:29:02Z]
6870
EOF
69-
close $ofh;
71+
close $ofh;
72+
}
73+
74+
{
75+
open my $ofh , '>', "$json_dir/Test-YAML.json";
76+
print $ofh <<'EOF';
77+
[{"archname":"x86_64-linux-multi","fulldate":"201610080752","distribution":"Test-YAML","osname":"linux","version":"1.06","status":"UNKNOWN","perl":"5.25.5","guid":"34e0a544-8d2c-11e6-8a2d-a149d3687cca","tester":"Serguei Trouchelle (STRO)"}]
78+
EOF
79+
close $ofh;
80+
}
7081

71-
my $exptected_IPC_System_Simple_ndjson_contents = <<'EOF';
82+
my $expected_IPC_System_Simple_ndjson_contents = <<'EOF';
7283
{"archname":"i86pc-solaris-thread-multi-64","distribution":"IPC-System-Simple","fulldate":"202510180759","guid":"6bad3778-abf8-11f0-8c1e-b80f595f57ba","osname":"solaris","perl":"5.43.4","status":"PASS","tester":"Carlos Guevara","version":"1.30"}
7384
EOF
74-
my $exptected_threads_ndjson_contents = <<'EOF';
85+
my $expected_threads_ndjson_contents = <<'EOF';
7586
{"archname":"amd64-netbsd-thread-multi","distribution":"threads","fulldate":"202510180759","guid":"67e088d4-abf8-11f0-97a1-bb460411313d","osname":"netbsd","perl":"5.43.4","status":"UNKNOWN","tester":"Carlos Guevara","version":"2.21"}
7687
EOF
7788
my $expected_Text_Tabs_Wrap_ndjson_contents = <<'EOF';
7889
{"archname":"i86pc-solaris-thread-multi-64","distribution":"Text-Tabs+Wrap","fulldate":"202510180740","guid":"b50809d2-abf5-11f0-ab63-d1797d8a4f3d","osname":"solaris","perl":"5.43.4","status":"PASS","tester":"Carlos Guevara","version":"2024.001"}
90+
EOF
91+
92+
my $expected_Test_YAML_ndjson_contents = <<'EOF';
93+
{"archname":"x86_64-linux-multi","distribution":"Test-YAML","fulldate":"201610080752","guid":"34e0a544-8d2c-11e6-8a2d-a149d3687cca","osname":"linux","perl":"5.25.5","status":"UNKNOWN","tester":"Serguei Trouchelle (STRO)","version":"1.06"}
94+
{"archname":"amd64-netbsd-thread-multi","distribution":"Test-YAML","fulldate":"202510180729","guid":"1e9545e2-abf4-11f0-8398-beaf3347c81e","osname":"netbsd","perl":"5.43.4","status":"PASS","tester":"Carlos Guevara","version":"1.07"}
7995
EOF
8096

8197
for my $pass (1..2) {
@@ -85,16 +101,43 @@ EOF
85101
like $err, qr{\QIPC-System-Simple.ndjson... (first-time creation) (no existing \E.*/log-as-json/IPC-System-Simple.json\Q...) (writing data...)}, "expected diagnostics for IPC-System-Simple (pass $pass)";
86102
like $err, qr{\Qthreads.ndjson... (first-time creation) (no existing \E.*/log-as-json/threads.json\Q...) (writing data...)}, "expected diagnostics for threads (pass $pass)";
87103
like $err, qr{\QText-Tabs+Wrap.ndjson... (first-time creation) (no existing \E.*/log-as-json/Text-Tabs\+Wrap.json\Q...) (writing data...)}, "expected diagnostics for Text-Tabs+Wrap (pass $pass)";
104+
like $err, qr{\QTest-YAML.ndjson... (first-time creation) (use data from existing \E.*/log-as-json/Test-YAML.json\Q...) (writing data...)}, "expected diagnostics for Test-YAML (pass $pass)";
88105
} else {
89106
like $err, qr{\QIPC-System-Simple.ndjson... (append to existing ndjson file...) (found last guid...) (no new data found...)}, "expected diagnostics for IPC-System-Simple (pass $pass)";
90107
like $err, qr{\Qthreads.ndjson... (append to existing ndjson file...) (found last guid...) (no new data found...)}, "expected diagnostics for threads (pass $pass)";
91108
like $err, qr{\QText-Tabs+Wrap.ndjson... (append to existing ndjson file...) (found last guid...) (no new data found...)}, "expected diagnostics for Text-Tabs+Wrap (pass $pass)";
109+
like $err, qr{\QTest-YAML.ndjson... (append to existing ndjson file...) (found last guid...) (no new data found...)}, "expected diagnostics for Test-YAML (pass $pass)";
92110
}
93111
like $err, qr{\QCannot parse dist '/' in line '[2025-10-18T07:54:07Z] [Chris Williams (BINGOS)] [pass] [/] [x86_64-linux] [perl-v5.18.2] [a018b394-abf7-11f0-a3bc-a055f9c4ba34] [2025-10-18T07:54:07Z]'}, 'unparsable dist';
94-
is slurp("$ndjson_dir/IPC-System-Simple.ndjson"), $exptected_IPC_System_Simple_ndjson_contents, 'IPC-System-Simple.ndjson contents OK';
95-
is slurp("$ndjson_dir/threads.ndjson"), $exptected_threads_ndjson_contents, 'threads.ndjson contents OK';
112+
is slurp("$ndjson_dir/IPC-System-Simple.ndjson"), $expected_IPC_System_Simple_ndjson_contents, 'IPC-System-Simple.ndjson contents OK';
113+
is slurp("$ndjson_dir/threads.ndjson"), $expected_threads_ndjson_contents, 'threads.ndjson contents OK';
114+
is slurp("$ndjson_dir/Text-Tabs+Wrap.ndjson"), $expected_Text_Tabs_Wrap_ndjson_contents, 'Text-Tabs+Wrap.ndjson contents OK';
115+
is slurp("$ndjson_dir/Test-YAML.ndjson"), $expected_Test_YAML_ndjson_contents, 'Test-YAML.ndjson contents OK';
116+
my @ndjson_files = <$ndjson_dir/*>;
117+
is scalar(@ndjson_files), 4, 'expected number of files';
118+
}
119+
120+
{
121+
# overwrite, simulating new contents
122+
open my $ofh, '>', $logtxt;
123+
print $ofh <<'EOF';
124+
The last 1000 reports as of 2025-10-18T08:00:04Z:
125+
[2025-10-18T07:47:59Z] [Carlos Guevara] [pass] [TINITA/Test-YAML-1.07.tar.gz] [i86pc-solaris-thread-multi-64] [perl-v5.43.4] [c4b21958-abf6-11f0-9c1b-c4a53ce7e222] [2025-10-18T07:47:59Z]
126+
[2025-10-18T07:29:02Z] [Carlos Guevara] [pass] [TINITA/Test-YAML-1.07.tar.gz] [amd64-netbsd-thread-multi] [perl-v5.43.4] [1e9545e2-abf4-11f0-8398-beaf3347c81e] [2025-10-18T07:29:02Z]
127+
EOF
128+
close $ofh;
129+
}
130+
131+
my $expected_Test_YAML_ndjson_contents_2 = $expected_Test_YAML_ndjson_contents . <<'EOF';
132+
{"archname":"i86pc-solaris-thread-multi-64","distribution":"Test-YAML","fulldate":"202510180747","guid":"c4b21958-abf6-11f0-9c1b-c4a53ce7e222","osname":"solaris","perl":"5.43.4","status":"PASS","tester":"Carlos Guevara","version":"1.07"}
133+
EOF
134+
{
135+
run(\@cmd, '2>', \my $err) or fail "@cmd failed";
136+
diag "command: @cmd\nstderr:\n$err" if $debug;
137+
like $err, qr{\QTest-YAML.ndjson... (append to existing ndjson file...) (found last guid...) (appending data...)}, "expected diagnostics for Test-YAML (appending data)";
138+
is slurp("$ndjson_dir/Test-YAML.ndjson"), $expected_Test_YAML_ndjson_contents_2, 'Test-YAML.ndjson contents OK';
96139
my @ndjson_files = <$ndjson_dir/*>;
97-
is scalar(@ndjson_files), 3, 'expected number of files';
140+
is scalar(@ndjson_files), 4, 'expected number of files';
98141
}
99142
}
100143

0 commit comments

Comments
 (0)