Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t/subcommands/build.t] fleshed out

31 tests run, 30 of which fail. (The remaining passing test asserts that we
"don't do anything" in a certain situation. I believe it serves its purpose
even though it passes right now.)
  • Loading branch information...
commit 3612ad05e818e524487657cbd3099b77ec2d988f 1 parent 6519911
Carl Mäsak authored
Showing with 96 additions and 9 deletions.
  1. +9 −1 lib/App/Pls.pm
  2. +87 −8 t/subcommands/build.t
10 lib/App/Pls.pm
View
@@ -1,6 +1,6 @@
use v6;
-enum State <gone fetched>;
+enum State <gone fetched built>;
enum Result <success failure>;
role App::Pls::ProjectsState {
@@ -12,9 +12,13 @@ class App::Pls::ProjectsState::Hash does App::Pls::ProjectsState {
role App::Pls::Fetcher {
}
+role App::Pls::Builder {
+}
+
class App::Pls::Core {
has App::Pls::ProjectsState $!projects;
has App::Pls::Fetcher $!fetcher;
+ has App::Pls::Builder $!builder;
method state-of($project) {
return -1;
@@ -23,4 +27,8 @@ class App::Pls::Core {
method fetch(*@projects) {
return;
}
+
+ method build(*@projects) {
+ return;
+ }
}
95 t/subcommands/build.t
View
@@ -1,18 +1,97 @@
use v6;
use Test;
-# [T] Build a project: Succeed.
+use App::Pls;
-# [T] Build an unfetched project: Fetch, build.
+my %projects =
+ fetched => { :state<fetched> },
+ unfetched => {},
+ "won't-fetch" => {},
+ "won't-build" => { :state<fetched> },
+ # RAKUDO: Need quotes around keys starting with 'has-' [perl #75694]
+ 'has-deps' => { :state<fetched>, :deps<A B> },
+ A => { :state<fetched> },
+ B => { :state<fetched>, :deps<C D> },
+ C => {},
+ D => { :state<fetched> },
+ circ-deps => { :state<fetched>, :deps<E> },
+ E => { :state<fetched>, :deps<circ-deps> },
+ dirdep-fails => { :state<fetched>, :deps<will-fail> },
+ indir-fails => { :state<fetched>, :deps<dirdep-fails> },
+;
-# [T] Build an unfetched project; fetch fails. Fail.
+my @actions;
-# [T] Build a project; a build error occurs: Fail.
+class Mock::Fetcher does App::Pls::Builder {
+}
-# [T] Build a project with dependencies: Build dependencies first.
+class Mock::Builder does App::Pls::Builder {
+}
-# [T] Build a project with circular dependencies: Fail.
+my $core = App::Pls::Core.new(
+ :projects(App::Pls::ProjectsState::Hash.new(%projects)),
+ :fetcher(Mock::Fetcher.new()),
+ :builder(Mock::Builder.new()),
+);
-# [T] Build a project whose direct dependency fails: Fail.
+plan 31;
-# [T] Build a project whose indirect dependency fails: Fail.
+given $core {
+ # [T] Build a project: Succeed.
+ is .state-of('fetched'), fetched, "State before: 'fetched'";
+ is .build(<fetched>), success, "Building project succeeded";
+ is .state-of('fetched'), built, "State after: 'built'";
+
+ # [T] Build an unfetched project: Fetch, build.
+ @actions = ();
+ is .state-of('unfetched'), gone, "State before: 'gone'";
+ is .build(<unfetched>), success, "Building unfetched project succeeded";
+ is ~@actions, 'fetch[unfeched] build[unfetched]',
+ "Fetched the project before building it";
+ is .state-of('unfetched'), built, "State after of unfetched: 'built'";
+
+ # [T] Build an unfetched project; fetch fails. Fail.
+ @actions = ();
+ is .build(<won't-fetch>), failure, "Won't build if fetch fails"; # "
+ is ~@actions, "fetch[won't-fetch]", "Didn't try building";
+ is .state-of("won't-fetch"), gone, "State after of won't-fetch: unchanged";
+
+ # [T] Build a project; a build error occurs: Fail.
+ @actions = ();
+ is .build(<won't-build>), failure, "Won't build if build fails"; # "
+ is ~@actions, "fetch[won't-build] build[won't build]", "Tried building";
+ is .state-of("won't-build"), gone, "State after of won't-build: unchanged";
+
+ # [T] Build a project with dependencies: Build dependencies first.
+ @actions = ();
+ is .build(<has-deps>), success, "Building project with deps succeeds";
+ is ~@actions, "fetch[C] build[A] build[C] build[D] build[has-deps]",
+ "Fetch before build, build with postorder traversal";
+ is .state-of('has-deps'), built, "State after of has-deps: built";
+ for <A B C D> -> $dep {
+ is .state-of($dep), built, "State after of $dep: built";
+ }
+
+ # [T] Build a project with circular dependencies: Fail.
+ @actions = ();
+ is .build(<circ-deps>), failure, "Building project with circ deps fails";
+ is ~@actions, "", "Didn't even try to build anything";
+ is .state-of('circ-deps'), fetched, "State after of circ-deps: unchanged";
+ is .state-of('E'), fetched;
+
+ # [T] Build a project whose direct dependency fails: Fail.
+ is .build(<dirdep-fails>), failure, "Fail when direct dep fails to build";
+ is .state-of('dirdep-fails'), fetched,
+ "State after of dirdep-fails: unchanged";
+ is .state-of('will-fail'), fetched,
+ "State after of will-fail: unchanged";
+
+ # [T] Build a project whose indirect dependency fails: Fail.
+ is .build(<indir-fails>), failure, "Fail when indirect dep fails to build";
+ is .state-of('indir-fails'), fetched,
+ "State after of indir-fails: unchanged";
+ is .state-of('dirdep-fails'), fetched,
+ "State after of dirdep-fails: unchanged";
+ is .state-of('will-fail'), fetched,
+ "State after of will-fail: unchanged";
+}
Please sign in to comment.
Something went wrong with that request. Please try again.