Qore QUnit Module Reference  0.1
QUnit.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file QUnit.qm Qore user module for automatic testing
3 
4 
5 
6 
7 
8 
47 namespace QUnit {}
49 
52 
53 public:
54  public :
55  string m_type;
56  *string m_subType;
57  any m_value;
58 
59 public:
60  constructor(string type);
61 
62  constructor(string type, string subType);
63 
64  // test
65  abstract public bool equals(AbstractTestResult r);
66  abstract public string toString();
67 };
68 
71 
72 public:
73  constructor() ;
74 
75 
77  public bool equals(QUnit::AbstractTestResult r);
78 
79 
80  public string toString();
81 
82 };
83 
86 
87 public:
88  private :
89  *string m_detail;
90 
91 public:
92 
94  constructor() ;
95 
96 
98  constructor(string s) ;
99 
100 
102  public bool equals(QUnit::AbstractTestResult r);
103 
104 
105  public string toString();
106 
107 };
108 
111 
112 public:
113  constructor(any value) ;
114 
115 
117  public bool equals(QUnit::AbstractTestResult r);
118 
119 
120  public string toString();
121 
122 };
123 
126 
127 public:
128  constructor(hash value) ;
129 
130 
131  public bool equals(QUnit::AbstractTestResult r);
132 
133 
134  public string toString();
135 
136 };
137 
140 
141 public:
142  public :
145 
146 public:
147 
149 
151  constructor(string exceptionType) ;
152 
153 
155  private constructor(string exceptionType, string subType) ;
156 
157 
159  public bool equals(QUnit::AbstractTestResult r);
160 
161 
163  public string toString();
164 
165 };
166 
169 
170 public:
171  private :
172  string m_exceptionDetail;
173 
174 public:
175 
177 
180  constructor(string exceptionType, string exceptionDetail) ;
181 
182 
184  public bool equals(QUnit::AbstractTestResult r);
185 
186 
187  public string toString();
188 
189 
190  string getDetail();
191 
192 };
193 
196 
197 public:
198  private :
199  string m_exceptionRegexp;
200 
201 public:
202 
203  constructor(string exceptionType, string exceptionRegexp) ;
204 
205 
207  public bool equals(QUnit::AbstractTestResult r);
208 
209 
210  public string toString();
211 
212 };
213 
216 
217 public:
218  constructor(string exceptionType, string exceptionSubstring) ;
219 
220 
221  public string toString();
222 
223 };
224 
227 
228 public:
229  private :
231  string m_name;
232 
234  code m_code;
235 
238 
240  int num_asserts = 0;
241 
243  int num_asserts_ok = 0;
244 
247 
248 public:
249 
251  constructor(string name, code code, *softlist args);
252 
253 
255  run(QUnit::Test test);
256 
257 
258  static *string getStackPos(list stack);
259 
260  static string getPos(hash ex);
261 
264 
265 
267  string getName();
268 
269 
270  incAssertions();
271 
272 
273  incAssertionsOk();
274 
275 
276  incAssertionsSkip();
277 
278 
279  int getAssertionCount();
280 
281 
282  int getAssertionOkCount();
283 
284 
285  int getAssertionSkipCount();
286 
287 
288  setupThread();
289 
290 
291  restoreThread();
292 
293 
295  rename(string n_name);
296 
297 };
298 
301 
302 public:
303  private :
304  const PLAINQUIET = 0;
305  const PLAIN = 1;
306  const JUNIT = 2;
307 
308  const OUT_TYPES = (
309  "plainquiet" : PLAINQUIET,
310  "plain" : PLAIN,
311  "junit" : JUNIT,
312  );
313 
314  const RESULT_TYPE_DESCRIPTION = (
315  TEST_SUCCESS : ("desc": "Success", "junittag" : NOTHING), // Success does not have a junit child tag
316  TEST_FAILURE : ("desc": "FAILURE", "junittag" : "failure"),
317  TEST_ERROR : ("desc": "ERROR", "junittag" : "error"),
318  TEST_SKIPPED : ("desc": "Skipped", "junittag" : "skipped"),
319  );
320 
322  const OffsetColumn = 20;
323 
326 
327  list m_results = ();
328  int m_output;
329  *string m_comment;
330 
332 
337 
339  string m_name;
341  string m_version;
342 
344  int num_asserts = 0;
345 
347  int num_asserts_ok = 0;
348 
351 
352 public:
353 
354  public :
356  const Opts = (
357  "help" : "h,help",
358  "verbose" : "v,verbose:i+",
359  "quiet" : "q,quiet",
360  "format" : "format=s",
361  );
362 
363  const TEST_SUCCESS = 0;
364  const TEST_FAILURE = 1;
365  const TEST_ERROR = 2;
366  const TEST_SKIPPED = 3;
367 
368 public:
369 
370  private printOption(string left, string right, int offset = OffsetColumn);
371 
372 
373  private usageIntern(int offset = OffsetColumn);
374 
375 
376  private usage();
377 
378 
379  private processOptions(reference p_argv);
380 
381 
383 
388  constructor(string name, string version, *reference p_argv, hash opts = Opts);
389 
390 
391  private callPrinterFunction(string type, *softlist args);
392 
393 
394  private printHeader() { callPrinterFunction("header"); }
395  private printSummary() { callPrinterFunction("summary"); }
396  private printTestReport(hash testcase) { callPrinterFunction("testreport", testcase); }
397 
398  private printPlaintextHeader();
399 
400 
401  private printPlaintextSummary();
402 
403 
404  private printPlaintextOneTest(hash testcase);
405 
406 
407  private printJunitSummary();
408 
409 
411  int errors();
412 
413 
415  int skipped();
416 
417 
419  int testCount();
420 
421 
423  addTestResult(TestCase tc, int success, *string error, *string pos, *string detail);
424 
425 };
426 
429 
430 public:
431  private :
434 
435  static QUnit::TestResultSuccess RESULT_SUCCESS = new QUnit::TestResultSuccess();
436  static QUnit::TestResultFailure RESULT_FAILURE = new QUnit::TestResultFailure();
437 
438 public:
439 
441  constructor(string name, string version, *reference p_argv, *hash opts) ;
442 
443 
446 
449 
451  setUp() {}
452 
454  tearDown() {}
455 
457  *string getEnv(string key, *string def);
458 
459 
461 
470  addTestCase(string name, code call, *softlist args);
471 
472 
474 
482 
483 
485  private string printUnexpectedData(any exp, any act, *bool neg, *bool soft_comparisons);
486 
487 
488  private string shorten(any value);
489 
490 
491  private compare(any v1, any v2, reference out, string path, *bool soft_comparisons);
492 
493 
494  private compareHashes(hash h1, hash h2, reference out, string path = "", *bool soft_comparisons);
495 
496 
497  private compareLists(list l1, list l2, reference out, string path = "", *bool soft_comparisons);
498 
499 
500 //######## Assertions & test control functions
501 
503 
516  public any testAssertionValue(*string name, any actual, any expected);
517 
518 
520 
529  public assertEqSoft(any expected, any actual, *string name);
530 
531 
533 
542  public assertEq(any expected, any actual, *string name);
543 
544 
546 
556  public assertFloatEq(float expected, float actual, float epsilon = 0.0000000001, *string name);
557 
558 
560 
570  public assertNumberEq(number expected, number actual, number epsilon = 0.0000000001, *string name);
571 
572 
574 
582  public assertTrue(any actual, *string name);
583 
584 
586 
594  public assertFalse(any actual, *string name);
595 
596 
598 
608  public assertThrows(string expectedErr, *string expectedDesc, code theCode, *softlist args, *string name);
609 
610 
612 
621  public assertThrows(string expectedErr, code theCode, *softlist args, *string name);
622 
623 
625 
633  public assertSkip (*string name);
634 
635 
637  TestCase getTestCase(string meth);
638 
639 
641 
648  public fail(*string msg);
649 
650 
652 
659  public testNullAssertion(string name, code condition, *softlist args);
660 
661 
663 
671  public any testAssertion(string name, code condition, *softlist args, int expectedResultValue);
672 
673 
675 
683  public any testAssertion(string name, code condition, *softlist args, float expectedResultValue);
684 
685 
687 
695  public any testAssertion(string name, code condition, *softlist args, number expectedResultValue);
696 
697 
699 
707  public any testAssertion(string name, code condition, *softlist args, bool expectedResultValue);
708 
709 
711 
719  public any testAssertion(string name, code condition, *softlist args, string expectedResultValue);
720 
721 
723 
731  public any testAssertion(string name, code condition, *softlist args, date expectedResultValue);
732 
733 
735 
743  public any testAssertion(string name, code condition, *softlist args, binary expectedResultValue);
744 
745 
747 
755  public any testAssertion(string name, code condition, *softlist args, hash expectedResultValue);
756 
757 
759 
767  public any testAssertion(string name, code condition, *softlist args, list expectedResultValue);
768 
769 
771 
779  public any testAssertion(string name, code condition, *softlist args, QUnit::AbstractTestResult expectedResult = new QUnit::TestResultSuccess());
780 
781 
782  private any testAssertionIntern(TestCase tc, string name, QUnit::AbstractTestResult actualResult, QUnit::AbstractTestResult expectedResult, any ret, *string pos);
783 
784 
786 
789  public testSkip(string reason);
790 
791 
792 //######## Test conditions passable to test assertions
793 
795 
801  bool equals(any a, any b);
802 
803 
805 
811  bool notEquals(any a, any b);
812 
813 
815 
821  bool regexpMatches(string s, string regexp);
822 
823 
825 
831  bool equalsIterated(AbstractIterator a, AbstractIterator b);
832 
833 
834 //######## Main function and test running helpers
835 
837  int main();
838 
839 
841  static string getAssertionName(*string name);
842 };
843 
846 
847 public:
848  private :
849  *string m_testedFile;
850  Program m_child;
851  *hash m_modules;
852 
853  static bool instantiated = False;
854 
855 public:
856 
857  constructor(string name, string version, *reference p_argv, *hash opts) ;
858 
859 
861  setScriptPath(*string testedFile);
862 
863 
865  setUp() { }
866  tearDown() { }
867 
868  private Program createInjectedProgram();
869 
870 
871  abstract performInjections(Program p);
872  abstract performModuleInjections();
873 
874  private injectIntoModule(string module);
875 
876 
877  destructor();
878 
879 
880  int main();
881 
882 };
883 
884 class QUnit::DependencyInjectedTestRunner : public QUnit::Test {
885 
886 public:
887  public setScriptPath(*string testedFile) {}
888  private injectIntoModule(string module) {}
889 
890  constructor(string name, string version, *reference p_argv, *hash opts) ;
891 
892 };
date date(date dt)
public string toString()
returns a string describing the exception type
Class representing Exception of a particular type with a particular detail message.
Definition: QUnit.qm.dox.h:168
public assertEqSoft(any expected, any actual, *string name)
Tests a value for equality to an expected value with soft comparisons (types may differ) ...
Class representing any non-boolean value.
Definition: QUnit.qm.dox.h:110
number exp(number n)
string m_name
the name of the test case
Definition: QUnit.qm.dox.h:231
addTestResult(TestCase tc, int success, *string error, *string pos, *string detail)
adds a test result
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
A class representing a test with injected dependencies.
Definition: QUnit.qm.dox.h:845
Class representing a partial match of a hash value. Common keys have to be identical.
Definition: QUnit.qm.dox.h:125
tearDown()
Prototype function for cleaning up test environemnt. It will be called after each test has executed...
Definition: QUnit.qm.dox.h:454
const OffsetColumn
the default column offset for printing options used in printOption() and usageIntern() ...
Definition: QUnit.qm.dox.h:322
public assertTrue(any actual, *string name)
Tests a boolean value.
public testNullAssertion(string name, code condition, *softlist args)
Tests for a single assertion for a call returning no value (for example, to ensure that the call does...
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
TestCase getTestCase(string meth)
returns the current test case
Class representing Exception of a particular type and substring for detail.
Definition: QUnit.qm.dox.h:215
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
constructor(string name, string version, *reference p_argv, hash opts=Opts)
creates the object from the arguments
An abstract class representing test result interface.
Definition: QUnit.qm.dox.h:51
Class representing Exception of a particular type.
Definition: QUnit.qm.dox.h:139
int num_asserts_skip
total number of skipped assertions in script
Definition: QUnit.qm.dox.h:350
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
number number(softnumber n)
public assertSkip(*string name)
Skips assertion on purpose.
int num_asserts
number of assertions in current test case
Definition: QUnit.qm.dox.h:240
constructor()
Instantiate an unspecific failure, no detail.
setScriptPath(*string testedFile)
A helper function. It must be called once for a new instance with get_script_path() as argument...
binary binary()
Class representing boolean True.
Definition: QUnit.qm.dox.h:70
public string toString()
returns a string describing the exception type
bool equals(any a, any b)
Compare two values for equality.
int num_asserts
total number of assertions in script
Definition: QUnit.qm.dox.h:344
public any testAssertionValue(*string name, any actual, any expected)
Tests a value for equality to an expected value.
const False
Class containing the configuration for a test case.
Definition: QUnit.qm.dox.h:226
string m_exceptionType
corresponds to the "err" key of an exception hash (the first value of a throw statement) ...
Definition: QUnit.qm.dox.h:144
setUp()
A prototype function.
Definition: QUnit.qm.dox.h:865
list list(...)
the main namespace for all public definitions in the QUnit module
Definition: QUnit.qm.dox.h:48
public any testAssertion(string name, code condition, *softlist args, int expectedResultValue)
Tests for a single assertion for a call returning an integer value and returns the value generated...
public string toString()
returns a string describing the exception type
hash m_options
the result of parsing command-line options with Qore::GetOpt::parse2()
Definition: QUnit.qm.dox.h:336
Base class for collecting test results and reporting.
Definition: QUnit.qm.dox.h:300
int num_asserts_ok
number of successful assertions in current test case
Definition: QUnit.qm.dox.h:243
constructor(string exceptionType, string exceptionDetail)
creates the object from the exception arguments
constructor(string exceptionType)
creates the object from the exception arguments
private string printUnexpectedData(any exp, any act, *bool neg, *bool soft_comparisons)
Helper function for printing out human-readable comparison of two values.
public assertEq(any expected, any actual, *string name)
Tests a value for equality to an expected value with hard comparisons (types and values must be ident...
constructor(string name, string version, *reference p_argv, *hash opts)
creates the object and sets the name of the test
hash m_printMethods
A map of print methods, categorised into three types: header, summary, testreport.
Definition: QUnit.qm.dox.h:325
globalTearDown()
global tear down; will be called once after all tests are run
Definition: QUnit.qm.dox.h:448
public assertNumberEq(number expected, number actual, number epsilon=0.0000000001, *string name)
Tests a number value for equality to an expected value with an allowed error.
string m_name
test case name
Definition: QUnit.qm.dox.h:339
public string toString()
returns a string describing the exception type
int main()
Run the whole suite, report results.
bool equalsIterated(AbstractIterator a, AbstractIterator b)
Compare two iterables, item by item, for equality of each index.
addTestCase(string name, code call, *softlist args)
adds a test case to run
int errors()
returns the number of errors encountered during test execution
public assertFalse(any actual, *string name)
Tests a boolean value.
string getName()
returns the test case name
string m_version
test case version
Definition: QUnit.qm.dox.h:341
string type(any arg)
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
Class representing Exception of a particular type and matching regexp for detail. ...
Definition: QUnit.qm.dox.h:195
const NOTHING
int num_asserts_ok
total number of successful assertions in script
Definition: QUnit.qm.dox.h:347
checkException(QUnit::Test test, hash e)
handles exceptions raised while running the TestCase
static string getAssertionName(*string name)
returns the assertion name for display purposes
public fail(*string msg)
Fails the test unconditionally.
globalSetUp()
global setup; will be called once before tests are run
Definition: QUnit.qm.dox.h:445
int num_asserts_skip
number of skipped assertions in current test case
Definition: QUnit.qm.dox.h:246
bool regexpMatches(string s, string regexp)
Compare a string for match against a regexp.
bool notEquals(any a, any b)
Compare two values for inequality.
setUp()
Prototype function for setting up test environment. It will be called for each test individually...
Definition: QUnit.qm.dox.h:451
list testCases
list of test cases
Definition: QUnit.qm.dox.h:433
*list m_args
arguments to the above callable object
Definition: QUnit.qm.dox.h:237
run(QUnit::Test test)
runs the TestCase
constructor(string name, code code, *softlist args)
creates the TestCase object from the given arguments
public bool equals(QUnit::AbstractTestResult r)
Equality operator.
code m_code
the body of the test case
Definition: QUnit.qm.dox.h:234
public assertFloatEq(float expected, float actual, float epsilon=0.0000000001, *string name)
Tests a float value for equality to an expected value with an allowed error.
Class representing test function failure, both unspecific and with detail.
Definition: QUnit.qm.dox.h:85
int skipped()
returns the number of tests skipped
*string getEnv(string key, *string def)
facade for the system environment variables
hash hash(object obj)
const Opts
default options for Qore::GetOpt::constructor()
Definition: QUnit.qm.dox.h:356
rename(string n_name)
renames the test case
public testSkip(string reason)
Skips a given test, eg. because it may be missing some dependencies.
int testCount()
returns the total number of test results
public assertThrows(string expectedErr, *string expectedDesc, code theCode, *softlist args, *string name)
Tests that a piece of code throws an exception with given description.
Base class representing a simple test, implements an implicit main() function and all utility functio...
Definition: QUnit.qm.dox.h:428