Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[t/subcommands/test.t] fleshed out

34 tests run and fail.
  • Loading branch information...
commit 1c8c201495a162a330b1ad0a19ae28bce657c920 1 parent 3612ad0
Carl Mäsak authored

Showing 2 changed files with 109 additions and 8 deletions. Show diff stats Hide diff stats

  1. +8 1 lib/App/Pls.pm
  2. +101 7 t/subcommands/test.t
9 lib/App/Pls.pm
... ... @@ -1,6 +1,6 @@
1 1 use v6;
2 2
3   -enum State <gone fetched built>;
  3 +enum State <gone fetched built tested>;
4 4 enum Result <success failure>;
5 5
6 6 role App::Pls::ProjectsState {
@@ -15,6 +15,9 @@ role App::Pls::Fetcher {
15 15 role App::Pls::Builder {
16 16 }
17 17
  18 +role App::Pls::Tester {
  19 +}
  20 +
18 21 class App::Pls::Core {
19 22 has App::Pls::ProjectsState $!projects;
20 23 has App::Pls::Fetcher $!fetcher;
@@ -31,4 +34,8 @@ class App::Pls::Core {
31 34 method build(*@projects) {
32 35 return;
33 36 }
  37 +
  38 + method test(*@projects, Bool :$ignore-deps) {
  39 + return;
  40 + }
34 41 }
108 t/subcommands/test.t
... ... @@ -1,16 +1,110 @@
1 1 use v6;
2 2 use Test;
3 3
4   -# [T] Test a project: Succeed.
  4 +use App::Pls;
5 5
6   -# [T] Test an unbuilt project: Build, test.
  6 +my %projects =
  7 + untested => { :state<built> },
  8 + unbuilt => { :state<fetched> },
  9 + unfetched => {},
  10 + "won't-test" => { :state<built> },
  11 + "won't-build" => { :state<fetched> },
  12 + "won't-fetch" => {},
  13 + "won't-build-2" => {},
  14 + # RAKUDO: Need quotes around keys starting with 'has-' [perl #75694]
  15 + 'has-deps' => { :state<built>, :deps<A B> },
  16 + A => { :state<built> },
  17 + B => { :state<fetched>, :deps<C D> },
  18 + C => {},
  19 + D => { :state<fetched> },
  20 + ignore-deps => { :state<built>, :deps<E F G> },
  21 + E => {},
  22 + F => { :state<fetched> },
  23 + G => { :state<built> },
  24 +;
7 25
8   -# [T] Test an unbuilt project; build fails. Fail.
  26 +my @actions;
9 27
10   -# [T] Test an unfetched project: Fetch, build, test.
  28 +class Mock::Fetcher does App::Pls::Fetcher {
  29 +}
11 30
12   -# [T] Test an unfetched project; fetch fails. Fail.
  31 +class Mock::Builder does App::Pls::Builder {
  32 +}
13 33
14   -# [T] Test an unfetched project; build fails. Fail.
  34 +class Mock::Tester does App::Pls::Tester {
  35 +}
15 36
16   -# [T] Test a project whose tests fail: Fail.
  37 +my $core = App::Pls::Core.new(
  38 + :projects(App::Pls::ProjectsState::Hash.new(%projects)),
  39 + :fetcher(Mock::Fetcher.new()),
  40 + :builder(Mock::Builder.new()),
  41 + :tester(Mock::Tester.new()),
  42 +);
  43 +
  44 +plan 34;
  45 +
  46 +given $core {
  47 + # [T] Test a project: Succeed.
  48 + is .state-of("untested"), built, "State before: 'built'";
  49 + is .test(<untested>), success, "Testing the project succeeds";
  50 + is .state-of("untested"), tested, "State after: 'tested'";
  51 +
  52 + # [T] Test an unbuilt project: Build, test.
  53 + @actions = ();
  54 + is .state-of("unbuilt"), fetched, "State before: 'fetched'";
  55 + is .test(<unbuilt>), success, "Build and test succeeds";
  56 + is ~@actions, 'build[unbuilt] test[unbuilt]', "Order is correct";
  57 + is .state-of("unbuilt"), tested, "State after: 'tested'";
  58 +
  59 + # [T] Test an unbuilt project; build fails. Fail.
  60 + @actions = ();
  61 + is .test(<won't-build>), failure, "Won't build, and thus won't test"; #'
  62 + is ~@actions, "build[won't-build]", "Tried building, not testing";
  63 + is .state-of("won't-build"), fetched, "State after: unchanged";
  64 +
  65 + # [T] Test an unfetched project: Fetch, build, test.
  66 + @actions = ();
  67 + is .test(<unfetched>), success, "Fetch, build and test succeeds";
  68 + is ~@actions, 'fetch[unfetched] build[unfetched] test[unfetched]',
  69 + "Order is correct";
  70 + is .state-of("unfetched"), tested, "State after: 'tested'";
  71 +
  72 + # [T] Test an unfetched project; fetch fails. Fail.
  73 + is .test(<won't-fetch>), failure, "Won't fetch and thus won't test"; #'
  74 + is ~@actions, "fetch[won't-fetch]",
  75 + "Tried fetching, not building or testing";
  76 + is .state-of("won't-fetch"), gone, "State after: unchanged";
  77 +
  78 + # [T] Test an unfetched project; build fails. Fail.
  79 + @actions = ();
  80 + is .test(<won't-build-2>), failure, "Won't build, and thus won't test"; #'
  81 + is ~@actions, "fetch[won't-build-2] build[won't-build-2]",
  82 + "Order is correct";
  83 + is .state-of("won't-build-2"), fetched, "State after: 'fetched'";
  84 +
  85 + # [T] Test a project whose tests fail: Fail.
  86 + is .test(<won't-test>), failure, "Won't test"; #"
  87 + is .state-of("won't-test"), built, "State after: 'built'";
  88 +
  89 + # [T] Test a project with dependencies: fetch, build, test dependencies
  90 + @actions = ();
  91 + is .test(<has-deps>), success, "Test a project with dependencies";
  92 + is ~@actions,
  93 + 'fetch[C] build[D] build[B] '
  94 + ~ 'test[A] test[C] test[D] test[B] test[has-deps]',
  95 + "Fetch first, then build (postorder), then test (postorder)";
  96 + is .state-of("has-deps"), tested, "State after of has-deps: 'tested'";
  97 + for <A B C D> -> $dep {
  98 + is .state-of($dep), tested, "State after of $dep: 'tested'";
  99 + }
  100 +
  101 + # [T] Test a projects with dependencies, but explicitly ignoring the
  102 + # dependencies: test only the project, do not fetch/build dependencies
  103 + @actions = ();
  104 + is .test(<ignore-deps>, :ignore-deps), success, "Test-ignore-deps works";
  105 + is ~@actions, 'test[ignore-deps]', "Only ignore-deps is tested";
  106 + is .state-of("ignore-deps"), tested, "State after: 'tested'";
  107 + is .state-of("E"), gone, "State after of E: unchanged";
  108 + is .state-of("F"), fetched, "State after of F: unchanged";
  109 + is .state-of("G"), built, "State after of G: unchanged";
  110 +}

0 comments on commit 1c8c201

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