aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs65
1 files changed, 47 insertions, 18 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
index 05a8756..713b280 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
@@ -25,12 +25,14 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
28using System.IO; 29using System.IO;
29using System.CodeDom.Compiler; 30using System.CodeDom.Compiler;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using Microsoft.CSharp; 32using Microsoft.CSharp;
32using NUnit.Framework; 33using NUnit.Framework;
33using OpenSim.Region.ScriptEngine.Shared.CodeTools; 34using OpenSim.Region.ScriptEngine.Shared.CodeTools;
35using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
34using OpenSim.Tests.Common; 36using OpenSim.Tests.Common;
35 37
36namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests 38namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
@@ -47,6 +49,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
47 private CSharpCodeProvider m_CSCodeProvider; 49 private CSharpCodeProvider m_CSCodeProvider;
48 private CompilerParameters m_compilerParameters; 50 private CompilerParameters m_compilerParameters;
49 private CompilerResults m_compilerResults; 51 private CompilerResults m_compilerResults;
52 private ResolveEventHandler m_resolveEventHandler;
50 53
51 /// <summary> 54 /// <summary>
52 /// Creates a temporary directory where build artifacts are stored. 55 /// Creates a temporary directory where build artifacts are stored.
@@ -66,9 +69,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
66 m_CSCodeProvider = new CSharpCodeProvider(); 69 m_CSCodeProvider = new CSharpCodeProvider();
67 m_compilerParameters = new CompilerParameters(); 70 m_compilerParameters = new CompilerParameters();
68 71
69 string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin"); 72 string rootPath = System.AppDomain.CurrentDomain.BaseDirectory;
73
74 m_resolveEventHandler = new ResolveEventHandler(AssemblyResolver.OnAssemblyResolve);
75
76 System.AppDomain.CurrentDomain.AssemblyResolve += m_resolveEventHandler;
77
70 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); 78 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
71 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); 79 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
80 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenMetaverseTypes.dll"));
72 m_compilerParameters.GenerateExecutable = false; 81 m_compilerParameters.GenerateExecutable = false;
73 } 82 }
74 83
@@ -79,6 +88,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
79 [TestFixtureTearDown] 88 [TestFixtureTearDown]
80 public void CleanUp() 89 public void CleanUp()
81 { 90 {
91 System.AppDomain.CurrentDomain.AssemblyResolve -= m_resolveEventHandler;
92
82 if (Directory.Exists(m_testDir)) 93 if (Directory.Exists(m_testDir))
83 { 94 {
84 // Blow away the temporary directory with artifacts. 95 // Blow away the temporary directory with artifacts.
@@ -90,7 +101,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
90 /// Test the C# compiler error message can be mapped to the correct 101 /// Test the C# compiler error message can be mapped to the correct
91 /// line/column in the LSL source when an undeclared variable is used. 102 /// line/column in the LSL source when an undeclared variable is used.
92 /// </summary> 103 /// </summary>
93 //[Test] 104 [Test]
94 public void TestUseUndeclaredVariable() 105 public void TestUseUndeclaredVariable()
95 { 106 {
96 TestHelpers.InMethod(); 107 TestHelpers.InMethod();
@@ -106,25 +117,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
106}"; 117}";
107 118
108 CSCodeGenerator cg = new CSCodeGenerator(); 119 CSCodeGenerator cg = new CSCodeGenerator();
109 string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + 120 string output = cg.Convert(input);
110 "namespace SecondLife { " + 121
111 "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + 122 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
112 "public Script() { } " + 123// System.Console.WriteLine(output);
113 cg.Convert(input) + 124
114 "} }\n";
115 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap; 125 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
116 126
117 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); 127 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
118 128//
119 Assert.AreEqual(new KeyValuePair<int, int>(5, 21), 129// foreach (KeyValuePair<int, int> key in positionMap.Keys)
120 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); 130// {
131// KeyValuePair<int, int> val = positionMap[key];
132//
133// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
134// }
135//
136// foreach (CompilerError compErr in m_compilerResults.Errors)
137// {
138// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
139// }
140
141 Assert.AreEqual(
142 new KeyValuePair<int, int>(5, 21),
143 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
121 } 144 }
122 145
123 /// <summary> 146 /// <summary>
124 /// Test that a string can be cast to string and another string 147 /// Test that a string can be cast to string and another string
125 /// concatenated. 148 /// concatenated.
126 /// </summary> 149 /// </summary>
127 //[Test] 150 [Test]
128 public void TestCastAndConcatString() 151 public void TestCastAndConcatString()
129 { 152 {
130 TestHelpers.InMethod(); 153 TestHelpers.InMethod();
@@ -143,15 +166,21 @@ default
143 } 166 }
144}"; 167}";
145 168
169// System.Console.WriteLine(input);
146 CSCodeGenerator cg = new CSCodeGenerator(); 170 CSCodeGenerator cg = new CSCodeGenerator();
147 string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + 171 string output = cg.Convert(input);
148 "namespace SecondLife { " + 172
149 "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + 173 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
150 "public Script() { } " + 174// System.Console.WriteLine(output);
151 cg.Convert(input) + 175
152 "} }\n";
153 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); 176 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
154 177
178 System.Console.WriteLine("ERRORS: {0}", m_compilerResults.Errors.Count);
179 foreach (CompilerError compErr in m_compilerResults.Errors)
180 {
181 System.Console.WriteLine("Error: {0}", compErr);
182 }
183
155 Assert.AreEqual(0, m_compilerResults.Errors.Count); 184 Assert.AreEqual(0, m_compilerResults.Errors.Count);
156 } 185 }
157 } 186 }