<commit_before>#!perl

use Test::More;
use strict;
use FindBin qw($Bin);
use English qw( -no_match_vars );

require "$Bin/helper.pl";

my $file_slurp_available = load_mod("File::Slurp qw(read_file)");

my $profile_filename = ( lc($OSNAME) eq 'darwin' ) ? '.profile' : '.bashrc';

# TODO test dry run

subtest 'uninstall dotfiles' => sub {
    my ( $home, $repo ) = minimum_home_with_ssh('uninstall');
    symlink( "/anywhere/else", "$home/.other" );
    mkdir("$home/.backup");
    mkdir("$home/.backup/bin");
    mkdir("$home/.backup/bin/preexisting");
    mkdir("$home/.ssh/.backup");
    mkdir("$home/.ssh/.backup/config");
    mkdir("$home/.ssh/.backup/config/preexisting");

    my $output = `HOME=$home perl $repo/bin/dfm --verbose`;

    ok( -d "$home/.backup", 'main backup dir exists' );
    ok( -l "$home/bin",     'bin is a symlink' );

    my $output = `HOME=$home perl $repo/bin/dfm --verbose uninstall`;

    ok( !-l "$home/bin",            'bin is no longer a symlink' );
    ok( -e "$home/bin/preexisting", 'bin from backup is restored' );
    ok( -l "$home/.other",          'other symlink still exists' );

    ok( !-l "$home/.ssh/config", '.ssh/config is no longer a symlink' );
    ok( -e "$home/.ssh/config/preexisting",
        '.ssh/config from backup is restored'
    );

SKIP: {
        skip 'File::Slurp not found', 1 unless $file_slurp_available;

        ok( read_file("$home/$profile_filename") !~ /bashrc.load/,
            "loader absent in $profile_filename" );
    }
};

done_testing;<commit_msg>implemented dry run test for uninstall<commit_after>#!perl

use Test::More;
use strict;
use FindBin qw($Bin);
use English qw( -no_match_vars );

require "$Bin/helper.pl";

my $file_slurp_available = load_mod("File::Slurp qw(read_file)");

my $profile_filename = ( lc($OSNAME) eq 'darwin' ) ? '.profile' : '.bashrc';

subtest 'uninstall dotfiles' => sub {
    my ( $home, $repo ) = minimum_home_with_ssh('uninstall');
    extra_setup($home);

    my $output = `HOME=$home perl $repo/bin/dfm --verbose`;

    ok( -d "$home/.backup", 'main backup dir exists' );
    ok( -l "$home/bin",     'bin is a symlink' );

    my $output = `HOME=$home perl $repo/bin/dfm --verbose uninstall`;

    ok( !-l "$home/bin",            'bin is no longer a symlink' );
    ok( -e "$home/bin/preexisting", 'bin from backup is restored' );
    ok( -l "$home/.other",          'other symlink still exists' );

    ok( !-l "$home/.ssh/config", '.ssh/config is no longer a symlink' );
    ok( -e "$home/.ssh/config/preexisting",
        '.ssh/config from backup is restored'
    );

SKIP: {
        skip 'File::Slurp not found', 1 unless $file_slurp_available;

        ok( read_file("$home/$profile_filename") !~ /bashrc.load/,
            "loader absent in $profile_filename" );
    }
};

subtest 'uninstall dotfiles (dry-run)' => sub {
    my ( $home, $repo ) = minimum_home_with_ssh('uninstall');
    extra_setup($home);

    my $output = `HOME=$home perl $repo/bin/dfm --verbose`;

    ok( -d "$home/.backup", 'main backup dir exists' );
    ok( -l "$home/bin",     'bin is a symlink' );

    my $output
        = `HOME=$home perl $repo/bin/dfm --dry-run --verbose uninstall`;

    ok( -l "$home/bin", 'bin is still a symlink' );

    ok( -l "$home/.ssh/config", '.ssh/config is still a symlink' );

SKIP: {
        skip 'File::Slurp not found', 1 unless $file_slurp_available;

        ok( read_file("$home/$profile_filename") =~ /bashrc.load/,
            "loader still exists in $profile_filename"
        );
    }
};

done_testing;

sub extra_setup {
    my $home = shift;

    symlink( "/anywhere/else", "$home/.other" );
    mkdir("$home/.backup");
    mkdir("$home/.backup/bin");
    mkdir("$home/.backup/bin/preexisting");
    mkdir("$home/.ssh/.backup");
    mkdir("$home/.ssh/.backup/config");
    mkdir("$home/.ssh/.backup/config/preexisting");
}
{'fraction_non_alphanumeric': 0.18520434557682358, 'fraction_numerical': 0.0007759958613554061, 'mean_word_length': 2.9378818737270875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7102700', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1362, 'n_words': 336}