Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t/subcommands/test.t] fleshed out

34 tests run and fail.
  • Loading branch information...
commit 1c8c201495a162a330b1ad0a19ae28bce657c920 1 parent 3612ad0
Carl Mäsak authored
Showing with 109 additions and 8 deletions.
  1. +8 −1 lib/App/Pls.pm
  2. +101 −7 t/subcommands/test.t
9 lib/App/Pls.pm
View
@@ -1,6 +1,6 @@
use v6;
-enum State <gone fetched built>;
+enum State <gone fetched built tested>;
enum Result <success failure>;
role App::Pls::ProjectsState {
@@ -15,6 +15,9 @@ role App::Pls::Fetcher {
role App::Pls::Builder {
}
+role App::Pls::Tester {
+}
+
class App::Pls::Core {
has App::Pls::ProjectsState $!projects;
has App::Pls::Fetcher $!fetcher;
@@ -31,4 +34,8 @@ class App::Pls::Core {
method build(*@projects) {
return;
}
+
+ method test(*@projects, Bool :$ignore-deps) {
+ return;
+ }
}
108 t/subcommands/test.t
View
@@ -1,16 +1,110 @@
use v6;
use Test;
-# [T] Test a project: Succeed.
+use App::Pls;
-# [T] Test an unbuilt project: Build, test.
+my %projects =
+ untested => { :state<built> },
+ unbuilt => { :state<fetched> },
+ unfetched => {},
+ "won't-test" => { :state<built> },
+ "won't-build" => { :state<fetched> },
+ "won't-fetch" => {},
+ "won't-build-2" => {},
+ # RAKUDO: Need quotes around keys starting with 'has-' [perl #75694]
+ 'has-deps' => { :state<built>, :deps<A B> },
+ A => { :state<built> },
+ B => { :state<fetched>, :deps<C D> },
+ C => {},
+ D => { :state<fetched> },
+ ignore-deps => { :state<built>, :deps<E F G> },
+ E => {},
+ F => { :state<fetched> },
+ G => { :state<built> },
+;
-# [T] Test an unbuilt project; build fails. Fail.
+my @actions;
-# [T] Test an unfetched project: Fetch, build, test.
+class Mock::Fetcher does App::Pls::Fetcher {
+}
-# [T] Test an unfetched project; fetch fails. Fail.
+class Mock::Builder does App::Pls::Builder {
+}
-# [T] Test an unfetched project; build fails. Fail.
+class Mock::Tester does App::Pls::Tester {
+}
-# [T] Test a project whose tests fail: Fail.
+my $core = App::Pls::Core.new(
+ :projects(App::Pls::ProjectsState::Hash.new(%projects)),
+ :fetcher(Mock::Fetcher.new()),
+ :builder(Mock::Builder.new()),
+ :tester(Mock::Tester.new()),
+);
+
+plan 34;
+
+given $core {
+ # [T] Test a project: Succeed.
+ is .state-of("untested"), built, "State before: 'built'";
+ is .test(<untested>), success, "Testing the project succeeds";
+ is .state-of("untested"), tested, "State after: 'tested'";
+
+ # [T] Test an unbuilt project: Build, test.
+ @actions = ();
+ is .state-of("unbuilt"), fetched, "State before: 'fetched'";
+ is .test(<unbuilt>), success, "Build and test succeeds";
+ is ~@actions, 'build[unbuilt] test[unbuilt]', "Order is correct";
+ is .state-of("unbuilt"), tested, "State after: 'tested'";
+
+ # [T] Test an unbuilt project; build fails. Fail.
+ @actions = ();
+ is .test(<won't-build>), failure, "Won't build, and thus won't test"; #'
+ is ~@actions, "build[won't-build]", "Tried building, not testing";
+ is .state-of("won't-build"), fetched, "State after: unchanged";
+
+ # [T] Test an unfetched project: Fetch, build, test.
+ @actions = ();
+ is .test(<unfetched>), success, "Fetch, build and test succeeds";
+ is ~@actions, 'fetch[unfetched] build[unfetched] test[unfetched]',
+ "Order is correct";
+ is .state-of("unfetched"), tested, "State after: 'tested'";
+
+ # [T] Test an unfetched project; fetch fails. Fail.
+ is .test(<won't-fetch>), failure, "Won't fetch and thus won't test"; #'
+ is ~@actions, "fetch[won't-fetch]",
+ "Tried fetching, not building or testing";
+ is .state-of("won't-fetch"), gone, "State after: unchanged";
+
+ # [T] Test an unfetched project; build fails. Fail.
+ @actions = ();
+ is .test(<won't-build-2>), failure, "Won't build, and thus won't test"; #'
+ is ~@actions, "fetch[won't-build-2] build[won't-build-2]",
+ "Order is correct";
+ is .state-of("won't-build-2"), fetched, "State after: 'fetched'";
+
+ # [T] Test a project whose tests fail: Fail.
+ is .test(<won't-test>), failure, "Won't test"; #"
+ is .state-of("won't-test"), built, "State after: 'built'";
+
+ # [T] Test a project with dependencies: fetch, build, test dependencies
+ @actions = ();
+ is .test(<has-deps>), success, "Test a project with dependencies";
+ is ~@actions,
+ 'fetch[C] build[D] build[B] '
+ ~ 'test[A] test[C] test[D] test[B] test[has-deps]',
+ "Fetch first, then build (postorder), then test (postorder)";
+ is .state-of("has-deps"), tested, "State after of has-deps: 'tested'";
+ for <A B C D> -> $dep {
+ is .state-of($dep), tested, "State after of $dep: 'tested'";
+ }
+
+ # [T] Test a projects with dependencies, but explicitly ignoring the
+ # dependencies: test only the project, do not fetch/build dependencies
+ @actions = ();
+ is .test(<ignore-deps>, :ignore-deps), success, "Test-ignore-deps works";
+ is ~@actions, 'test[ignore-deps]', "Only ignore-deps is tested";
+ is .state-of("ignore-deps"), tested, "State after: 'tested'";
+ is .state-of("E"), gone, "State after of E: unchanged";
+ is .state-of("F"), fetched, "State after of F: unchanged";
+ is .state-of("G"), built, "State after of G: unchanged";
+}
Please sign in to comment.
Something went wrong with that request. Please try again.