App-Dapper
view release on metacpan or search on metacpan
t/57-deploy.t view on Meta::CPAN
for my $setting ("command: ''", "command:\n run: x", "command: [a, b]", "command: ~") {
spew('_config.yml', "---\nname: x\ndeploy:\n $setting\n");
is(error_of(sub { deploy() }), "error: deploy.command in _config.yml must be a command to run\n", "\"$setting\" is not a command");
}
};
subtest 'GitHub Pages' => sub {
plan skip_all => 'git is not installed' unless $has_git;
local $ENV{GIT_AUTHOR_NAME} = 'Test';
local $ENV{GIT_AUTHOR_EMAIL} = 'test@example.com';
local $ENV{GIT_COMMITTER_NAME} = 'Test';
local $ENV{GIT_COMMITTER_EMAIL} = 'test@example.com';
my $remote = tempdir(CLEANUP => 1) . '/site.git';
system('git', 'init', '--quiet', '--bare', $remote) == 0 or plan skip_all => 'git init failed';
my $git = sub { my $out = `git --git-dir='$remote' @_`; return $out };
make_site({ %site, '_config.yml' => "---\nname: Pages Site\ndeploy:\n github_pages:\n repo: $remote\n branch: site\n" });
spew('_output/.dapper-reload', "1\n");
my ($result, $out) = deploy_output();
is($result, 1, 'returns 1');
like($out, qr/^Starting a new site branch$/m, 'says it starts a new branch');
like($out, qr/^\+ git init --quiet /m, 'shows the git commands');
like($out, qr/^Deployed (\d+) changed file\(s\) to site of \Q$remote\E\n\z/m, 'says how many files it deployed, and where');
my $files = $git->('ls-tree -r --name-only site');
like($files, qr/^index\.html$/m, 'pushed to the branch named');
like($files, qr/^\.nojekyll$/m, '.nojekyll added');
unlike($files, qr/^CNAME$/m, 'no CNAME without cname');
unlike($files, qr/dapper-reload/, '.dapper-reload is not published');
is($git->('log -1 --format=%s site'), "Deploy Pages Site (" . (() = $files =~ /\n/g) . " file(s) changed)\n", 'the commit says what changed');
is($git->('log -1 --format=%an site'), "Test\n", "committed as git's user");
is($git->('branch --list gh-pages'), '', 'gh-pages is not made');
($result, $out) = deploy_output();
like($out, qr/^Nothing changed since the last deploy to site\.\n\z/m, 'nothing to deploy');
is($git->('rev-list --count site') + 0, 1, 'and no commit');
spew('_source/new.md', "---\ntitle: New\n---\nNew\n");
($result, $out) = deploy_output(undef, dry_run => 1);
like($out, qr/^Dry run: would commit \d+ changed file\(s\) to site of \Q$remote\E:$/m, 'a dry run says what it would commit');
like($out, qr/^A new\.html$/m, 'listing the changes');
is($git->('rev-list --count site') + 0, 1, 'and commits nothing');
like($out, qr/^\+ git clone --quiet --branch site -- \Q$remote\E /m, 'the existing branch is cloned in full from a local path');
($result, $out) = deploy_output(undef, no_build => 1);
is($git->('rev-list --count site') + 0, 2, 'a second deploy adds a commit');
like($git->('ls-tree -r --name-only site'), qr/^new\.html$/m, 'with the new page');
};
subtest 'GitHub Pages settings' => sub {
plan skip_all => 'git is not installed' unless $has_git;
local $ENV{GIT_AUTHOR_NAME} = 'Test';
local $ENV{GIT_AUTHOR_EMAIL} = 'test@example.com';
local $ENV{GIT_COMMITTER_NAME} = 'Test';
local $ENV{GIT_COMMITTER_EMAIL} = 'test@example.com';
local $ENV{GIT_CEILING_DIRECTORIES} = File::Spec->tmpdir;
my $remote = tempdir(CLEANUP => 1) . '/site.git';
system('git', 'init', '--quiet', '--bare', $remote) == 0 or plan skip_all => 'git init failed';
make_site({ %site, '_config.yml' => "---\nname: x\ndeploy:\n github_pages: true\n" });
{
open(my $stderr, '>&', \*STDERR);
open(STDERR, '>', File::Spec->devnull);
my $error = error_of(sub { deploy() });
open(STDERR, '>&', $stderr);
is($error, "error: deploy.github_pages in _config.yml needs a repo (or run dapper in a git repository with an origin)\n", 'without a repo or an origin');
}
is(system('git', 'init', '--quiet', '.'), 0, 'the site is a git repository');
is(system('git', 'remote', 'add', 'origin', $remote), 0, 'with an origin');
ok(deploy(), 'with the origin of the repository dapper runs in');
like(`git --git-dir='$remote' ls-tree -r --name-only gh-pages`, qr/^index\.html$/m, 'to gh-pages by default');
make_site({ %site, '_config.yml' => "---\nname: x\ndeploy:\n github_pages:\n repo: $remote\n cname: docs.example.com\n" });
ok(deploy(), 'with a cname');
is(`git --git-dir='$remote' show gh-pages:CNAME`, "docs.example.com\n", 'CNAME written');
is(`git --git-dir='$remote' rev-list --count gh-pages` + 0, 2, 'on top of the history that was there');
my $url = tempdir(CLEANUP => 1) . '/url.git';
system('git', 'init', '--quiet', '--bare', $url) == 0 or return;
make_site({ %site, 'css/site.css' => "body {}\n", '_config.yml' => "---\ndeploy:\n github_pages:\n repo: file://$url\n" });
ok(deploy(), 'a repository given as a URL');
spew('_source/more.md', "---\ntitle: More\n---\nMore\n");
my ($result, $out) = deploy_output();
like($out, qr/^\+ git clone --quiet --depth 1 --branch gh-pages -- file:\/\/\Q$url\E /m, 'is cloned shallow');
is(`git --git-dir='$url' rev-list --count gh-pages` + 0, 2, 'and deployed again');
like(`git --git-dir='$url' ls-tree -r --name-only gh-pages`, qr/^css\/site\.css$/m, 'folders in the output are replaced too');
like(`git --git-dir='$url' log -1 --format=%s gh-pages`, qr/^Deploy the site \(\d+ file\(s\) changed\)$/, 'a site without a name is "the site"');
local $ENV{PATH} = $bin;
is(error_of(sub { deploy(undef, no_build => 1) }), "error: deploying to GitHub Pages needs git\n", 'without git');
};
done_testing();
( run in 1.532 second using v1.01-cache-2.11-cpan-60884a8df76 )