From 246adcc1f9933f47d95f8c756ea2715f7ffced23 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 24 May 2022 19:53:26 +0200 Subject: [PATCH] Added some rudimentary unittests that should have their order enforced else stuff can go really wrong, these things run as part of a single process, no restarts etc. Hence state is persisted across unittests --- source/tasky/jobs.d | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/source/tasky/jobs.d b/source/tasky/jobs.d index 17a1167..dcb2dc8 100644 --- a/source/tasky/jobs.d +++ b/source/tasky/jobs.d @@ -319,6 +319,100 @@ public abstract class Descriptor : Signal } + /** + * Tests custom descriptor IDs + * + * FIXME: The unittest ordering to be kinda important + */ + + unittest + { + /** + * Add a descriptor with ID 1, this should pass + */ + try + { + class DescTest : Descriptor + { + this() + { + super(1); + } + + public override void handler(Event e) + { + writeln("Event id ", e.id); + } + } + + Descriptor newDesc = new DescTest(); + assert(newDesc.getDescriptorClass() == 1); + } + catch(DescriptorException e) + { + assert(false); + } + + } + + unittest + { + /** + * Add a descriptor with ID 2, this should pass + */ + try + { + class DescTest : Descriptor + { + this() + { + super(2); + } + + public override void handler(Event e) + { + writeln("Event id ", e.id); + } + } + + Descriptor newDesc = new DescTest(); + assert(newDesc.getDescriptorClass() == 2); + } + catch(DescriptorException e) + { + assert(false); + } + } + + unittest + { + /** + * Add a descriptor with ID 2, this should pass + */ + try + { + class DescTest : Descriptor + { + this() + { + super(2); + } + + public override void handler(Event e) + { + writeln("Event id ", e.id); + } + } + + Descriptor newDesc = new DescTest(); + assert(false); + } + catch(DescriptorException e) + { + assert(true); + } + } + unittest {