-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAddToSourceControl.cls
More file actions
172 lines (140 loc) · 5.43 KB
/
AddToSourceControl.cls
File metadata and controls
172 lines (140 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Import SourceControl.Git
Class UnitTest.SourceControl.Git.Utils.AddToSourceControl Extends UnitTest.SourceControl.Git.AbstractTest
{
Property RoutineMappingCreated As %Boolean [ InitialExpression = 0 ];
Property PackageMappingCreated As %Boolean [ InitialExpression = 0 ];
Method %OnNew(initvalue) As %Status
{
Set sc = ##super(initvalue)
If $$$ISERR(sc) Quit sc
Set settings = ##class(SourceControl.Git.Settings).%New()
Set settings.Mappings("MAC","*") = "rtn/"
Do settings.%Save()
Quit $$$OK
}
Method %OnClose() As %Status [ Private, ServerOnly = 1 ]
{
// Clean up routines
if ##class(%Routine).Exists("%gitunittestroutine.mac") {
do ##class(%Routine).Delete("%gitunittestroutine.mac")
}
if ##class(%Routine).Exists("gitunittestroutine.mac") {
do ##class(%Routine).Delete("gitunittestroutine.mac")
}
// Clean up classes
if $$$defClassDefined("%gitunittest.TestClass") {
do $system.OBJ.Delete("%gitunittest.TestClass.CLS", "-d")
}
if $$$defClassDefined("gitunittest.TestClass") {
do $system.OBJ.Delete("gitunittest.TestClass.CLS", "-d")
}
// Clean up mappings
if ..RoutineMappingCreated {
do ..DeleteRoutineMapping("%gitunittest*")
}
if ..PackageMappingCreated {
do ..DeletePackageMapping("%gitunittest")
}
Quit ##super()
}
/// Returns the name of the default routine database for this namespace.
Method GetDefaultDBName() As %String
{
set defaultDB = ##class(%SYS.Namespace).GetRoutineDest($namespace, "gitunittestroutine.mac")
quit ##class(%File).GetDirectoryPiece(defaultDB, ##class(%File).GetDirectoryLength(defaultDB))
}
/// Creates a routine mapping in %SYS so that routines matching the given pattern
/// resolve to the current namespace's default routine database.
Method CreateRoutineMapping(pattern As %String) As %Status
{
set ns = $namespace
set defaultDBName = ..GetDefaultDBName()
new $namespace
set $namespace = "%SYS"
set props("Database") = defaultDBName
set sc = ##class(Config.MapRoutines).Create(ns, pattern, .props)
quit sc
}
/// Creates a package mapping in %SYS so that classes in the given package
/// resolve to the current namespace's default routine database.
Method CreatePackageMapping(package As %String) As %Status
{
set ns = $namespace
set defaultDBName = ..GetDefaultDBName()
new $namespace
set $namespace = "%SYS"
set props("Database") = defaultDBName
set sc = ##class(Config.MapPackages).Create(ns, package, .props)
quit sc
}
/// Deletes a routine mapping from %SYS for the given pattern.
ClassMethod DeleteRoutineMapping(pattern As %String) As %Status
{
set ns = $namespace
new $namespace
set $namespace = "%SYS"
quit ##class(Config.MapRoutines).Delete(ns, pattern)
}
/// Deletes a package mapping from %SYS for the given package.
ClassMethod DeletePackageMapping(package As %String) As %Status
{
set ns = $namespace
new $namespace
set $namespace = "%SYS"
quit ##class(Config.MapPackages).Delete(ns, package)
}
Method TestNonPercentRoutine()
{
set internalName = "gitunittestroutine.mac"
set r = ##class(%Routine).%New(internalName)
do r.WriteLine(" write ""hello"",!")
$$$ThrowOnError(r.Save())
// Verify FullExternalName returns a non-empty path
set fullName = ##class(Utils).FullExternalName(internalName)
do $$$AssertNotEquals(fullName, "")
// Add to source control and verify it exported to the file system
do $$$AssertStatusOK(##class(Utils).AddToSourceControl(internalName))
do $$$AssertTrue(##class(%File).Exists(fullName), "non-% routine file should exist on disk after AddToSourceControl")
}
Method TestPercentRoutine()
{
set internalName = "%gitunittestroutine.mac"
$$$ThrowOnError(..CreateRoutineMapping("%gitunittest*"))
set ..RoutineMappingCreated = 1
// Create a routine named %gitunittestroutine.mac
set r = ##class(%Routine).%New(internalName)
do r.WriteLine(" write ""hello"",!")
$$$ThrowOnError(r.Save())
// Verify FullExternalName returns a non-empty path
set fullName = ##class(Utils).FullExternalName(internalName)
do $$$AssertNotEquals(fullName, "")
// Add to source control and verify it exported to the file system
do $$$AssertStatusOK(##class(Utils).AddToSourceControl(internalName))
do $$$AssertTrue(##class(%File).Exists(fullName), "% routine file should exist on disk after AddToSourceControl")
}
Method TestNonPercentClass()
{
set internalName = "gitunittest.TestClass.CLS"
set classDef = ##class(%Dictionary.ClassDefinition).%New()
set classDef.Name = "gitunittest.TestClass"
$$$ThrowOnError(classDef.%Save())
set fullName = ##class(Utils).FullExternalName(internalName)
do $$$AssertNotEquals(fullName, "", "FullExternalName should return a path for non-% class")
do $$$AssertStatusOK(##class(Utils).AddToSourceControl(internalName))
do $$$AssertTrue(##class(%File).Exists(fullName), "non-% class file should exist on disk after AddToSourceControl")
}
Method TestPercentClass()
{
set internalName = "%gitunittest.TestClass.CLS"
$$$ThrowOnError(..CreatePackageMapping("%gitunittest"))
set ..PackageMappingCreated = 1
set classDef = ##class(%Dictionary.ClassDefinition).%New()
set classDef.Name = "%gitunittest.TestClass"
$$$ThrowOnError(classDef.%Save())
$$$ThrowOnError($system.OBJ.Compile("%gitunittest.TestClass", "ck-d"))
set fullName = ##class(Utils).FullExternalName(internalName)
do $$$AssertNotEquals(fullName, "", "FullExternalName should return a path for % class")
do $$$AssertStatusOK(##class(Utils).AddToSourceControl(internalName))
do $$$AssertTrue(##class(%File).Exists(fullName), "% class file should exist on disk after AddToSourceControl")
}
}