Permalink
Browse files

Revising testing framework.

  • Loading branch information...
1 parent 63c6c94 commit 86f0f5322638e23dc02dee94f40bf6f58771a693 @wilkie committed May 6, 2010
View
@@ -62,7 +62,7 @@ DFILES_INTERFACES = interfaces/container.d
DFILES_MATH = math/random.d math/currency.d math/fixed.d math/integer.d math/common.d math/vector.d math/matrix.d math/mathobject.d
DFILES_OPENGL = opengl/window.d opengl/texture.d opengl/light.d
DFILES_SPECS = specs/test.d
-DFILES_TESTING = testing/dspec.d testing/support.d testing/logic.d
+DFILES_TESTING = spec/support.d spec/logic.d spec/itemspecification.d spec/packagespecification.d spec/modulespecification.d spec/specification.d
DFILES_SYNCH = synch/atomic.d synch/condition.d synch/barrier.d synch/mutex.d synch/semaphore.d synch/thread.d synch/timer.d
DFILES_RSC =
View
@@ -90,7 +90,7 @@ int _adEq(void[] a1, void[] a2, TypeInfo ti) {
// Description: This runtime function sorts an array and is invoked with
// the sort property: array.sort
-Array _adSort(Array a, TypeInfo ti) {
+void[] _adSort(void[] a, TypeInfo ti) {
return a;
}
@@ -1,22 +1,95 @@
-module testing.logic;
+/*
+ * specification.d
+ *
+ * This module implements a class that wraps the specification of a particular
+ * subsection of a module.
+ *
+ * Originated: May 6th, 2010
+ *
+ */
-public import testing.support : describe, done;
+module spec.itemspecification;
+
+import spec.support : describe, done;
+import spec.logic;
import djehuty;
import io.console;
-enum it {
- does,
- doesnt
+class ItemSpecification {
+
+ this(string name) {
+ _name = name.dup;
+ }
+
+ string name() {
+ return _name;
+ }
+
+ void add(string specification, it delegate() testBody) {
+ _tests[specification] = testBody;
+ }
+
+ // Description: This will run all tests.
+ // Returns: When all tests are successful, it returns true. It returns false otherwise.
+ bool all() {
+ bool ret = true;
+ foreach(test; _tests.values) {
+ if (!test()) {
+ ret = false;
+ }
+ }
+ return ret;
+ }
+
+ // Description: This will test a particular item.
+ // Returns: When the test is successful, it returns true. It returns false otherwise.
+ bool test(string name) {
+ it ret = _tests[name]();
+ return false;
+ }
+
+ int opApply(int delegate(ref string) loopBody) {
+ foreach(test; _tests.keys) {
+ if (loopBody(test)) {
+ return 1;
+ }
+ }
+ return 1;
+ }
+
+ // Description: Print out the specification of the package, which serves as
+ // documentation for the application.
+ string toString() {
+ // Item should do this
+ // Item should do that
+ string ret = "";
+
+ foreach(spec; _tests.keys) {
+ ret ~= _name ~ " " ~ spec ~ "\n";
+ }
+
+ return ret;
+ }
+
+private:
+
+ string _name;
+
+ it delegate()[string] _tests;
}
-class Test {
- this(char[] testClass, char[] specFile = "") {
+/*
+class Tester {
+ this(char[] testClass, char[] moduleName, char[] specFile = "") {
currentTest = testClass;
this.specFile = specFile;
}
+ void run() {
+ }
+
void logSubset(char[] subsetName) {
currentRegion = subsetName;
}
@@ -108,3 +181,4 @@ private:
char[] specFile;
char[] currentRegion;
}
+*/
View
@@ -0,0 +1,6 @@
+module spec.logic;
+
+enum it {
+ does,
+ doesnt
+}
@@ -0,0 +1,61 @@
+/*
+ * moduletester.d
+ *
+ * This module implements a class that will interface the testing of a module.
+ *
+ * Originated: May 6th, 2010
+ *
+ */
+
+module spec.modulespecification;
+
+import spec.itemspecification;
+
+import spec.support : describe, done;
+
+import djehuty;
+
+import io.console;
+
+class ModuleSpecification {
+ this(string name) {
+ _name = name.dup;
+ }
+
+ string name() {
+ return _name;
+ }
+
+ // Description: This function will run all tests associated with this
+ // module.
+ bool all() {
+ bool ret = true;
+ foreach(test; _tests.values) {
+ if(!test.all()) {
+ ret = false;
+ }
+ }
+ return ret;
+ }
+
+ // Description: This function will return a class representing the test
+ // given by the name.
+ // name: The name of the test.
+ // Returns: A class that can be used to run the test.
+ ItemSpecification test(string name) {
+ return _tests[name];
+ }
+
+ int opApply(int delegate(ref ItemSpecification) loopBody) {
+ foreach(test; _tests.values.sort) {
+ if (loopBody(test)) {
+ return 1;
+ }
+ }
+ return 1;
+ }
+
+private:
+ string _name;
+ ItemSpecification[string] _tests;
+}
@@ -0,0 +1,79 @@
+/*
+ * packagespecification.d
+ *
+ * This module implements a class that will provide an outlet to test an entire
+ * package.
+ *
+ * Originated: May 6th, 2010
+ *
+ */
+
+module spec.packagespecification;
+
+import spec.modulespecification;
+
+import djehuty;
+
+class PackageSpecification {
+ this(string name) {
+ _name = name.dup;
+ }
+
+ string name() {
+ return _name;
+ }
+
+ void add(string moduleName, ModuleSpecification spec) {
+ _modules[moduleName] = spec;
+ }
+
+ bool all() {
+ bool ret = true;
+ foreach(mod; _modules.values) {
+ if (!mod.all()) {
+ ret = false;
+ }
+ }
+ return ret;
+ }
+
+ ModuleSpecification test(string name) {
+ return _modules[name];
+ }
+
+ int opApply(int delegate(ref ModuleSpecification) loopBody) {
+ foreach(mod; _modules.values.sort) {
+ if (loopBody(mod)) {
+ return 1;
+ }
+ }
+ return 1;
+ }
+
+ // Description: Print out the specification of the package, which serves as
+ // documentation for the application.
+ string toString() {
+ // Package
+ // Module
+ // Item should do this
+ // Item should do that
+ string ret = "";
+
+ foreach(mod; _modules.values.sort) {
+ ret ~= mod.name ~ "\n";
+ foreach(item; mod) {
+ foreach(spec; item) {
+ ret ~= " " ~ item.name ~ " " ~ spec ~ "\n";
+ }
+ }
+ }
+
+ return ret;
+ }
+
+private:
+
+ string _name;
+
+ ModuleSpecification _modules[string];
+}
View
@@ -0,0 +1,76 @@
+/*
+ * specification.d
+ *
+ * This module facilitates specifying the application.
+ *
+ * Originated: May 6th, 2010
+ *
+ */
+
+module spec.specification;
+import spec.packagespecification;
+
+import djehuty;
+
+class Specification {
+static:
+
+ string name() {
+ return Djehuty.app.name;
+ }
+
+ void add(string packageName, PackageSpecification spec) {
+ _packages[packageName] = spec;
+ }
+
+ bool all() {
+ bool ret = true;
+ foreach(pack; _packages) {
+ if (!pack.all()) {
+ ret = false;
+ }
+ }
+ return false;
+ }
+
+ PackageSpecification test(string name) {
+ return _packages[name];
+ }
+
+ int opApply(int delegate(PackageSpecification) loopBody) {
+ foreach(pack; _packages.values.sort) {
+ if (loopBody(pack)) {
+ return 1;
+ }
+ }
+ return 1;
+ }
+
+ // Description: Print out the specification, which is documentation of
+ // the application.
+ string toString() {
+ // Package
+ // Module
+ // Item should do this
+ // Item should do that
+ string ret = "";
+
+ foreach(pack; _packages.values.sort) {
+ ret ~= pack.name ~ "\n";
+ foreach(mod; pack) {
+ ret ~= " " ~ mod.name ~ "\n";
+ foreach(item; mod) {
+ foreach(spec; item) {
+ ret ~= " " ~ item.name ~ " " ~ spec ~ "\n";
+ }
+ }
+ }
+ }
+
+ return ret;
+ }
+
+private:
+
+ PackageSpecification[string] _packages;
+}
File renamed without changes.
View
@@ -0,0 +1,12 @@
+module specs.runtime.array;
+
+import io.console;
+
+describe runtime() {
+ describe _adCmp() {
+ it should_handle_empty_arrays() {
+ int[] empty = [];
+ shouldNot(empty == [1,2,3]);
+ }
+ }
+}
View
No changes.
Oops, something went wrong.

0 comments on commit 86f0f53

Please sign in to comment.