Chandra

 view release on metacpan or  search on metacpan

t/97_pack.t  view on Meta::CPAN

        my $made = $p->_distribute_linux({ path => "$out/LinApp", success => 1 });
        ok($made->{success} && -f $made->{appimage_path}, 'an appimagetool that works gives the AppImage');
        unlink "$out/LinApp/linapp.desktop";
        like($p->_create_appimage("$out/LinApp", "$bin/appimagetool")->{error}, qr/Missing \.desktop file/, 'no desktop file, no AppImage');
    }
    is(Chandra::Pack::_find_command('surely-not-a-command-here'), undef, 'an unknown command is not found');
    {
        local $ENV{PATH} = '/nonexistent';
        local $ENV{HOME} = $dir;
        write_file("$dir/bin/foundhere", "#!/bin/sh\n");
        chmod 0755, "$dir/bin/foundhere";
        is(Chandra::Pack::_find_command('foundhere'), "$dir/bin/foundhere", 'a command is found in the home bin without which');
    }
}

# --- a Windows build with signing asked for ---
{
    my $out = "$dir/windows";
    mkdir $out or die;
    my $p = Chandra::Pack->new(script => $script, name => 'Win', output => $out, platform => 'windows', assets => "$dir/assets");
    $p->{sign_cert} = "$dir/cert.pfx";
    $p->{sign_password} = 'secret';
    @warned = ();
    my $result = $p->build;
    ok($result->{success}, 'the Windows build succeeds');
    ok(-f "$out/Win/win.bat", 'with its launcher');
    ok(scalar(grep { /signtool signing failed/ } @warned), 'and warns when signtool is missing');
}

# --- a macOS build, signed ad hoc and put on a disk image ---
SKIP: {
    skip 'macOS builds need darwin', 14 unless $^O eq 'darwin';
    my $out = "$dir/macos";
    mkdir $out or die;
    my $icns = write_file("$dir/icon.icns", 'icns bytes');
    my $p = Chandra::Pack->new(script => $script, name => 'Mac App', version => '1.2', output => $out, icon => $icns, assets => "$dir/assets", perl => '/no/such/perl');
    like($p->_generate_plist, qr/CFBundleIconFile/, 'the plist names the icon when there is one');
    my $result = $p->build;
    ok($result->{success}, 'the macOS build succeeds');
    ok(-f "$out/MacApp.app/Contents/Resources/app.icns", 'an icns icon is copied');
    ok(-x "$out/MacApp.app/Contents/MacOS/macapp", 'the launcher is compiled');
    ok(-f "$out/MacApp.app/Contents/Resources/assets/a.txt", 'assets are copied');
    my ($so) = glob("$out/MacApp.app/Contents/Resources/lib/auto/Cpanel/JSON/XS/XS.*");
    ok($so, 'the XS library of a dependency is copied');

    my $png = Chandra::Pack->new(script => $script, name => 'Png App', output => $out, icon => "$dir/icon.png");
    ok($png->build->{success}, 'a build with a png icon');
    ok(-f "$out/PngApp.app/Contents/Resources/app.icns", 'ends with an icns, made or copied');

    my $dist = Chandra::Pack->new(script => $script, name => 'Dist App', output => $out, distribute => 1);
    my $signed = $dist->build;
    ok($signed->{success}, 'an ad hoc signed build with a disk image succeeds') or diag($signed->{error});
    ok($signed->{signed} && -f $signed->{dmg_path}, 'signed, with the image written');

    like($dist->_codesign_macos("$out/nothing.app", '-')->{error}, qr/codesign failed/, 'signing a missing app fails');
    like($dist->_create_dmg_macos("$out/nothing.app")->{error}, qr/DMG creation failed/, 'imaging a missing app fails');
    my $note = $dist->_notarize_macos("$out/nothing.app");
    like($note->{error}, qr/Failed to create ZIP|Notarization failed/, 'notarising a missing app fails');
    Chandra::Pack->config(notary_keychain => 'profile');
    $note = $dist->_notarize_macos("$out/DistApp.app");
    like($note->{error}, qr/Notarization failed/, 'and notarising without credentials fails after the zip');
    Chandra::Pack->config(notary_keychain => undef);

    Chandra::Pack->config(identity => 'Not A Real Identity', apple_id => 'a', team_id => 't');
    my $bad = Chandra::Pack->new(script => $script, name => 'Bad Sign', output => $out, distribute => 1)->build;
    ok(!$bad->{success}, 'a signing identity that does not exist fails the distribution');
    Chandra::Pack->config(identity => undef, apple_id => undef, team_id => undef);

    my $nocc = Chandra::Pack->new(script => $script, name => 'No Compile', output => "$dir/icon.png");
    eval { $nocc->build };
    like($@, qr/Failed to compile macOS launcher|cannot|Not a directory|exists/i, 'a launcher that cannot be written dies');
}

done_testing;



( run in 1.175 second using v1.01-cache-2.11-cpan-3f962061493 )