#!/usr/bin/env perl

=head1 NAME

check_diff_in_test_cases - helper for checking and updating diffs in test cases

=cut

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2026 Xiyue Deng <manphiz@gmail.com>

This program is free software: you can redistribute it and/or modify it under
the terms of the SPDX-License-Identifier: GPL-2.0-or-later

=cut

use strict;
use warnings;

use Getopt::Long;

use FindBin qw($Bin);
use lib "$Bin/../lib";
use TestHelper;

my $update;
GetOptions (
    "update" => \$update,
);

foreach my $test_case (get_all_test_cases()) {
    my $tmp_dir = Path::Tiny->tempdir(
        TEMPLATE => "dh-make-elpa_XXXXXX",
    );
    my $work_dir = setup_temp_work_dir($test_case, $tmp_dir);
    run_dh_make_elpa_in_temp_work_dir($work_dir, is_team_package($test_case),
                                      "$Bin/../..", 1);

    my $test_case_name = $test_case->basename;

    if (!check_no_diff($test_case, $work_dir)) {
        if ($update) {
            print "Updating the expected output of test case " .
                "\"$test_case_name\"...";
            update_expected_output($test_case, $work_dir);
            print "done\n";
        }
    } else {
        print "No diff found in test case \"$test_case_name\".\n";
    }
}

__END__

=head1 SYNOPSIS

=over

=item check_diff_in_test_cases [--update]

=back

=head1 DESCRIPTION

B<check_diff_in_test_cases> runs each test cases under t/data and see if the
output produced by dh-make-elpa has any diff compared to the contents under the
corresponding `expected/' directory.

Please go over the diff and see whether those are expected.  If so, you can run
with `--update' so that the contents under the `expected/' will be updated
accordingly.

