Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 June 12, 2010
10  lib/App/Pls.pm
... ...
@@ -1,6 +1,6 @@
1 1
 use v6;
2 2
 
3  
-enum State <gone fetched>;
  3
+enum State <gone fetched built>;
4 4
 enum Result <success failure>;
5 5
 
6 6
 role App::Pls::ProjectsState {
@@ -12,9 +12,13 @@ class App::Pls::ProjectsState::Hash does App::Pls::ProjectsState {
12 12
 role App::Pls::Fetcher {
13 13
 }
14 14
 
  15
+role App::Pls::Builder {
  16
+}
  17
+
15 18
 class App::Pls::Core {
16 19
     has App::Pls::ProjectsState $!projects;
17 20
     has App::Pls::Fetcher       $!fetcher;
  21
+    has App::Pls::Builder       $!builder;
18 22
 
19 23
     method state-of($project) {
20 24
         return -1;
@@ -23,4 +27,8 @@ class App::Pls::Core {
23 27
     method fetch(*@projects) {
24 28
         return;
25 29
     }
  30
+
  31
+    method build(*@projects) {
  32
+        return;
  33
+    }
26 34
 }
95  t/subcommands/build.t
... ...
@@ -1,18 +1,97 @@
1 1
 use v6;
2 2
 use Test;
3 3
 
4  
-# [T] Build a project: Succeed.
  4
+use App::Pls;
5 5
 
6  
-# [T] Build an unfetched project: Fetch, build.
  6
+my %projects =
  7
+    fetched       => { :state<fetched> },
  8
+    unfetched     => {},
  9
+    "won't-fetch" => {},
  10
+    "won't-build" => { :state<fetched> },
  11
+    # RAKUDO: Need quotes around keys starting with 'has-' [perl #75694]
  12
+    'has-deps'   => { :state<fetched>, :deps<A B> },
  13
+    A            => { :state<fetched> },
  14
+    B            => { :state<fetched>, :deps<C D> },
  15
+    C            => {},
  16
+    D            => { :state<fetched> },
  17
+    circ-deps    => { :state<fetched>, :deps<E> },
  18
+    E            => { :state<fetched>, :deps<circ-deps> },
  19
+    dirdep-fails => { :state<fetched>, :deps<will-fail> },
  20
+    indir-fails  => { :state<fetched>, :deps<dirdep-fails> },
  21
+;
7 22
 
8  
-# [T] Build an unfetched project; fetch fails. Fail.
  23
+my @actions;
9 24
 
10  
-# [T] Build a project; a build error occurs: Fail.
  25
+class Mock::Fetcher does App::Pls::Builder {
  26
+}
11 27
 
12  
-# [T] Build a project with dependencies: Build dependencies first.
  28
+class Mock::Builder does App::Pls::Builder {
  29
+}
13 30
 
14  
-# [T] Build a project with circular dependencies: Fail.
  31
+my $core = App::Pls::Core.new(
  32
+    :projects(App::Pls::ProjectsState::Hash.new(%projects)),
  33
+    :fetcher(Mock::Fetcher.new()),
  34
+    :builder(Mock::Builder.new()),
  35
+);
15 36
 
16  
-# [T] Build a project whose direct dependency fails: Fail.
  37
+plan 31;
17 38
 
18  
-# [T] Build a project whose indirect dependency fails: Fail.
  39
+given $core {
  40
+    # [T] Build a project: Succeed.
  41
+    is .state-of('fetched'), fetched, "State before: 'fetched'";
  42
+    is .build(<fetched>), success, "Building project succeeded";
  43
+    is .state-of('fetched'), built, "State after: 'built'";
  44
+
  45
+    # [T] Build an unfetched project: Fetch, build.
  46
+    @actions = ();
  47
+    is .state-of('unfetched'), gone, "State before: 'gone'";
  48
+    is .build(<unfetched>), success, "Building unfetched project succeeded";
  49
+    is ~@actions, 'fetch[unfeched] build[unfetched]',
  50
+        "Fetched the project before building it";
  51
+    is .state-of('unfetched'), built, "State after of unfetched: 'built'";
  52
+
  53
+    # [T] Build an unfetched project; fetch fails. Fail.
  54
+    @actions = ();
  55
+    is .build(<won't-fetch>), failure, "Won't build if fetch fails"; # "
  56
+    is ~@actions, "fetch[won't-fetch]", "Didn't try building";
  57
+    is .state-of("won't-fetch"), gone, "State after of won't-fetch: unchanged";
  58
+
  59
+    # [T] Build a project; a build error occurs: Fail.
  60
+    @actions = ();
  61
+    is .build(<won't-build>), failure, "Won't build if build fails"; # "
  62
+    is ~@actions, "fetch[won't-build] build[won't build]", "Tried building";
  63
+    is .state-of("won't-build"), gone, "State after of won't-build: unchanged";
  64
+
  65
+    # [T] Build a project with dependencies: Build dependencies first.
  66
+    @actions = ();
  67
+    is .build(<has-deps>), success, "Building project with deps succeeds";
  68
+    is ~@actions, "fetch[C] build[A] build[C] build[D] build[has-deps]",
  69
+        "Fetch before build, build with postorder traversal";
  70
+    is .state-of('has-deps'), built, "State after of has-deps: built";
  71
+    for <A B C D> -> $dep {
  72
+        is .state-of($dep), built, "State after of $dep: built";
  73
+    }
  74
+
  75
+    # [T] Build a project with circular dependencies: Fail.
  76
+    @actions = ();
  77
+    is .build(<circ-deps>), failure, "Building project with circ deps fails";
  78
+    is ~@actions, "", "Didn't even try to build anything";
  79
+    is .state-of('circ-deps'), fetched, "State after of circ-deps: unchanged";
  80
+    is .state-of('E'), fetched;
  81
+
  82
+    # [T] Build a project whose direct dependency fails: Fail.
  83
+    is .build(<dirdep-fails>), failure, "Fail when direct dep fails to build";
  84
+    is .state-of('dirdep-fails'), fetched,
  85
+        "State after of dirdep-fails: unchanged";
  86
+    is .state-of('will-fail'), fetched,
  87
+        "State after of will-fail: unchanged";
  88
+
  89
+    # [T] Build a project whose indirect dependency fails: Fail.
  90
+    is .build(<indir-fails>), failure, "Fail when indirect dep fails to build";
  91
+    is .state-of('indir-fails'), fetched,
  92
+        "State after of indir-fails: unchanged";
  93
+    is .state-of('dirdep-fails'), fetched,
  94
+        "State after of dirdep-fails: unchanged";
  95
+    is .state-of('will-fail'), fetched,
  96
+        "State after of will-fail: unchanged";
  97
+}

0 notes on commit 3612ad0

Please sign in to comment.
Something went wrong with that request. Please try again.