aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-06-18 23:04:31 +0100
committerJustin Clark-Casey2014-08-02 00:49:21 +0100
commit924ca8e2e93c2b3541f5356ec8f18feb12217002 (patch)
treea81ea5ce0dffa76e9155b7a3dade5340ff86e524 /OpenSim/Region/ScriptEngine
parentIn compiler regression tests, setup and teardown structures for each test to ... (diff)
downloadopensim-SC_OLD-924ca8e2e93c2b3541f5356ec8f18feb12217002.zip
opensim-SC_OLD-924ca8e2e93c2b3541f5356ec8f18feb12217002.tar.gz
opensim-SC_OLD-924ca8e2e93c2b3541f5356ec8f18feb12217002.tar.bz2
opensim-SC_OLD-924ca8e2e93c2b3541f5356ec8f18feb12217002.tar.xz
refactor: Simplify compilation result tests by factoring out common code.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs116
1 files changed, 45 insertions, 71 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
index 7701605..938cb2e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
@@ -101,6 +101,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
101 } 101 }
102 } 102 }
103 103
104 private CompilerResults CompileScript(
105 string input, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap)
106 {
107 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");
108
109 CSCodeGenerator cg = new CSCodeGenerator();
110 string output = cg.Convert(input);
111
112 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
113 // System.Console.WriteLine(output);
114
115 positionMap = cg.PositionMap;
116
117 CompilerResults compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
118
119 // foreach (KeyValuePair<int, int> key in positionMap.Keys)
120 // {
121 // KeyValuePair<int, int> val = positionMap[key];
122 //
123 // System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
124 // }
125 //
126 // foreach (CompilerError compErr in m_compilerResults.Errors)
127 // {
128 // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
129 // }
130
131 return compilerResults;
132 }
133
104 /// <summary> 134 /// <summary>
105 /// Test that line number errors are resolved as expected when preceding code contains a jump. 135 /// Test that line number errors are resolved as expected when preceding code contains a jump.
106 /// </summary> 136 /// </summary>
@@ -109,9 +139,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
109 { 139 {
110 TestHelpers.InMethod(); 140 TestHelpers.InMethod();
111 141
112 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); 142 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
113 143
114 string input = @"default 144 CompilerResults compilerResults = CompileScript(
145@"default
115{ 146{
116 state_entry() 147 state_entry()
117 { 148 {
@@ -119,33 +150,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
119 @l; 150 @l;
120 i = 1; 151 i = 1;
121 } 152 }
122}"; 153}", out positionMap);
123
124 CSCodeGenerator cg = new CSCodeGenerator();
125 string output = cg.Convert(input);
126
127 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
128// System.Console.WriteLine(output);
129
130 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
131
132 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
133
134// foreach (KeyValuePair<int, int> key in positionMap.Keys)
135// {
136// KeyValuePair<int, int> val = positionMap[key];
137//
138// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
139// }
140//
141// foreach (CompilerError compErr in m_compilerResults.Errors)
142// {
143// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
144// }
145 154
146 Assert.AreEqual( 155 Assert.AreEqual(
147 new KeyValuePair<int, int>(7, 9), 156 new KeyValuePair<int, int>(7, 9),
148 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); 157 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
149 } 158 }
150 159
151 /// <summary> 160 /// <summary>
@@ -157,41 +166,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
157 { 166 {
158 TestHelpers.InMethod(); 167 TestHelpers.InMethod();
159 168
160 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); 169 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
161 170
162 string input = @"default 171 CompilerResults compilerResults = CompileScript(
172@"default
163{ 173{
164 state_entry() 174 state_entry()
165 { 175 {
166 integer y = x + 3; 176 integer y = x + 3;
167 } 177 }
168}"; 178}", out positionMap);
169
170 CSCodeGenerator cg = new CSCodeGenerator();
171 string output = cg.Convert(input);
172
173 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
174 // System.Console.WriteLine(output);
175
176 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
177
178 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
179 //
180 // foreach (KeyValuePair<int, int> key in positionMap.Keys)
181 // {
182 // KeyValuePair<int, int> val = positionMap[key];
183 //
184 // System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
185 // }
186 //
187 // foreach (CompilerError compErr in m_compilerResults.Errors)
188 // {
189 // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
190 // }
191 179
192 Assert.AreEqual( 180 Assert.AreEqual(
193 new KeyValuePair<int, int>(5, 21), 181 new KeyValuePair<int, int>(5, 21),
194 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); 182 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
195 } 183 }
196 184
197 /// <summary> 185 /// <summary>
@@ -203,9 +191,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
203 { 191 {
204 TestHelpers.InMethod(); 192 TestHelpers.InMethod();
205 193
206 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); 194 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
207 195
208 string input = @"string s = "" a string""; 196 CompilerResults compilerResults = CompileScript(
197@"string s = "" a string"";
209 198
210default 199default
211{ 200{
@@ -215,24 +204,9 @@ default
215 string tmp = (string) gAvatarKey + s; 204 string tmp = (string) gAvatarKey + s;
216 llSay(0, tmp); 205 llSay(0, tmp);
217 } 206 }
218}"; 207}", out positionMap);
219
220// System.Console.WriteLine(input);
221 CSCodeGenerator cg = new CSCodeGenerator();
222 string output = cg.Convert(input);
223
224 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
225// System.Console.WriteLine(output);
226
227 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
228
229 System.Console.WriteLine("ERRORS: {0}", m_compilerResults.Errors.Count);
230 foreach (CompilerError compErr in m_compilerResults.Errors)
231 {
232 System.Console.WriteLine("Error: {0}", compErr);
233 }
234 208
235 Assert.AreEqual(0, m_compilerResults.Errors.Count); 209 Assert.AreEqual(0, compilerResults.Errors.Count);
236 } 210 }
237 } 211 }
238} \ No newline at end of file 212} \ No newline at end of file