132
|
1 /**
|
|
2 * The runtime module exposes information specific to the D runtime code.
|
|
3 *
|
|
4 * Copyright: Copyright (C) 2005-2006 Sean Kelly. All rights reserved.
|
|
5 * License: BSD style: $(LICENSE)
|
|
6 * Authors: Sean Kelly
|
|
7 */
|
|
8 module tango.core.Runtime;
|
|
9
|
|
10
|
|
11 private
|
|
12 {
|
|
13 extern (C) bool rt_isHalting();
|
|
14
|
|
15 alias bool function() moduleUnitTesterType;
|
|
16 }
|
|
17
|
|
18
|
|
19 ////////////////////////////////////////////////////////////////////////////////
|
|
20 // Runtime
|
|
21 ////////////////////////////////////////////////////////////////////////////////
|
|
22
|
|
23
|
|
24 /**
|
|
25 * This struct encapsulates all functionality related to the underlying runtime
|
|
26 * module for the calling context.
|
|
27 */
|
|
28 struct Runtime
|
|
29 {
|
|
30 /**
|
|
31 * Returns true if the runtime is halting. Under normal circumstances,
|
|
32 * this will be set between the time that normal application code has
|
|
33 * exited and before module dtors are called.
|
|
34 *
|
|
35 * Returns:
|
|
36 * true if the runtime is halting.
|
|
37 */
|
|
38 static bool isHalting()
|
|
39 {
|
|
40 return rt_isHalting();
|
|
41 }
|
|
42
|
|
43
|
|
44 /**
|
|
45 * Overrides the default module unit tester with a user-supplied version.
|
|
46 *
|
|
47 * Params:
|
|
48 * h = The new unit tester. Set to null to use the default unit tester.
|
|
49 */
|
|
50 static void moduleUnitTester( moduleUnitTesterType h )
|
|
51 {
|
|
52 sm_moduleUnitTester = h;
|
|
53 }
|
|
54
|
|
55
|
|
56 private:
|
|
57 static moduleUnitTesterType sm_moduleUnitTester = null;
|
|
58 }
|
|
59
|
|
60
|
|
61 ////////////////////////////////////////////////////////////////////////////////
|
|
62 // Overridable Callbacks
|
|
63 ////////////////////////////////////////////////////////////////////////////////
|
|
64
|
|
65
|
|
66 /**
|
|
67 * This routine is called by the runtime to run module unit tests on startup.
|
|
68 * The user-supplied unit tester will be called if one has been supplied,
|
|
69 * otherwise all unit tests will be run in sequence.
|
|
70 *
|
|
71 * Returns:
|
|
72 * true if execution should continue after testing is complete and false if
|
|
73 * not. Default behavior is to return true.
|
|
74 */
|
|
75 extern (C) bool runModuleUnitTests()
|
|
76 {
|
|
77 if( Runtime.sm_moduleUnitTester is null )
|
|
78 {
|
|
79 foreach( m; ModuleInfo )
|
|
80 {
|
|
81 if( m.unitTest )
|
|
82 m.unitTest();
|
|
83 }
|
|
84 return true;
|
|
85 }
|
|
86 return Runtime.sm_moduleUnitTester();
|
|
87 }
|