aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs55
1 files changed, 37 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..badf82a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
31using Microsoft.CSharp; 31using Microsoft.CSharp;
32using NUnit.Framework; 32using NUnit.Framework;
33using OpenSim.Region.ScriptEngine.Shared.CodeTools; 33using OpenSim.Region.ScriptEngine.Shared.CodeTools;
34using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
34using OpenSim.Tests.Common; 35using OpenSim.Tests.Common;
35 36
36namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests 37namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
@@ -66,9 +67,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
66 m_CSCodeProvider = new CSharpCodeProvider(); 67 m_CSCodeProvider = new CSharpCodeProvider();
67 m_compilerParameters = new CompilerParameters(); 68 m_compilerParameters = new CompilerParameters();
68 69
69 string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin"); 70 string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory));
70 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); 71 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")); 72 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
73 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenMetaverseTypes.dll"));
72 m_compilerParameters.GenerateExecutable = false; 74 m_compilerParameters.GenerateExecutable = false;
73 } 75 }
74 76
@@ -90,7 +92,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
90 /// Test the C# compiler error message can be mapped to the correct 92 /// 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. 93 /// line/column in the LSL source when an undeclared variable is used.
92 /// </summary> 94 /// </summary>
93 //[Test] 95 [Test]
94 public void TestUseUndeclaredVariable() 96 public void TestUseUndeclaredVariable()
95 { 97 {
96 TestHelpers.InMethod(); 98 TestHelpers.InMethod();
@@ -106,25 +108,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
106}"; 108}";
107 109
108 CSCodeGenerator cg = new CSCodeGenerator(); 110 CSCodeGenerator cg = new CSCodeGenerator();
109 string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + 111 string output = cg.Convert(input);
110 "namespace SecondLife { " + 112
111 "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + 113 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
112 "public Script() { } " + 114// System.Console.WriteLine(output);
113 cg.Convert(input) + 115
114 "} }\n";
115 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap; 116 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
116 117
117 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); 118 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
118 119//
119 Assert.AreEqual(new KeyValuePair<int, int>(5, 21), 120// foreach (KeyValuePair<int, int> key in positionMap.Keys)
120 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); 121// {
122// KeyValuePair<int, int> val = positionMap[key];
123//
124// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
125// }
126//
127// foreach (CompilerError compErr in m_compilerResults.Errors)
128// {
129// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
130// }
131
132 Assert.AreEqual(
133 new KeyValuePair<int, int>(5, 21),
134 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
121 } 135 }
122 136
123 /// <summary> 137 /// <summary>
124 /// Test that a string can be cast to string and another string 138 /// Test that a string can be cast to string and another string
125 /// concatenated. 139 /// concatenated.
126 /// </summary> 140 /// </summary>
127 //[Test] 141 [Test]
128 public void TestCastAndConcatString() 142 public void TestCastAndConcatString()
129 { 143 {
130 TestHelpers.InMethod(); 144 TestHelpers.InMethod();
@@ -143,15 +157,20 @@ default
143 } 157 }
144}"; 158}";
145 159
160// System.Console.WriteLine(input);
146 CSCodeGenerator cg = new CSCodeGenerator(); 161 CSCodeGenerator cg = new CSCodeGenerator();
147 string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + 162 string output = cg.Convert(input);
148 "namespace SecondLife { " + 163
149 "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + 164 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
150 "public Script() { } " + 165// System.Console.WriteLine(output);
151 cg.Convert(input) + 166
152 "} }\n";
153 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); 167 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
154 168
169// foreach (CompilerError compErr in m_compilerResults.Errors)
170// {
171// System.Console.WriteLine("Error: {0}", compErr);
172// }
173
155 Assert.AreEqual(0, m_compilerResults.Errors.Count); 174 Assert.AreEqual(0, m_compilerResults.Errors.Count);
156 } 175 }
157 } 176 }