diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 7701605ed9..938cb2efe8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs @@ -101,82 +101,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests } } - /// - /// Test that line number errors are resolved as expected when preceding code contains a jump. - /// - [Test] - public void TestJumpAndSyntaxError() + private CompilerResults CompileScript( + string input, out Dictionary, KeyValuePair> positionMap) { - TestHelpers.InMethod(); - m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); - string input = @"default -{ - state_entry() - { - jump l; - @l; - i = 1; - } -}"; - - CSCodeGenerator cg = new CSCodeGenerator(); - string output = cg.Convert(input); - - output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); -// System.Console.WriteLine(output); - - Dictionary, KeyValuePair> positionMap = cg.PositionMap; - - m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); - -// foreach (KeyValuePair key in positionMap.Keys) -// { -// KeyValuePair val = positionMap[key]; -// -// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value); -// } -// -// foreach (CompilerError compErr in m_compilerResults.Errors) -// { -// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); -// } - - Assert.AreEqual( - new KeyValuePair(7, 9), - positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); - } - - /// - /// Test the C# compiler error message can be mapped to the correct - /// line/column in the LSL source when an undeclared variable is used. - /// - [Test] - public void TestUseUndeclaredVariable() - { - TestHelpers.InMethod(); - - m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); - - string input = @"default -{ - state_entry() - { - integer y = x + 3; - } -}"; - CSCodeGenerator cg = new CSCodeGenerator(); string output = cg.Convert(input); output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); // System.Console.WriteLine(output); - Dictionary, KeyValuePair> positionMap = cg.PositionMap; + positionMap = cg.PositionMap; + + CompilerResults compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); - m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); - // // foreach (KeyValuePair key in positionMap.Keys) // { // KeyValuePair val = positionMap[key]; @@ -189,9 +128,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); // } + return compilerResults; + } + + /// + /// Test that line number errors are resolved as expected when preceding code contains a jump. + /// + [Test] + public void TestJumpAndSyntaxError() + { + TestHelpers.InMethod(); + + Dictionary, KeyValuePair> positionMap; + + CompilerResults compilerResults = CompileScript( +@"default +{ + state_entry() + { + jump l; + @l; + i = 1; + } +}", out positionMap); + + Assert.AreEqual( + new KeyValuePair(7, 9), + positionMap[new KeyValuePair(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); + } + + /// + /// Test the C# compiler error message can be mapped to the correct + /// line/column in the LSL source when an undeclared variable is used. + /// + [Test] + public void TestUseUndeclaredVariable() + { + TestHelpers.InMethod(); + + Dictionary, KeyValuePair> positionMap; + + CompilerResults compilerResults = CompileScript( +@"default +{ + state_entry() + { + integer y = x + 3; + } +}", out positionMap); + Assert.AreEqual( new KeyValuePair(5, 21), - positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); + positionMap[new KeyValuePair(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); } /// @@ -203,9 +191,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests { TestHelpers.InMethod(); - m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); + Dictionary, KeyValuePair> positionMap; - string input = @"string s = "" a string""; + CompilerResults compilerResults = CompileScript( +@"string s = "" a string""; default { @@ -215,24 +204,9 @@ default string tmp = (string) gAvatarKey + s; llSay(0, tmp); } -}"; +}", out positionMap); -// System.Console.WriteLine(input); - CSCodeGenerator cg = new CSCodeGenerator(); - string output = cg.Convert(input); - - output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); -// System.Console.WriteLine(output); - - m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); - - System.Console.WriteLine("ERRORS: {0}", m_compilerResults.Errors.Count); - foreach (CompilerError compErr in m_compilerResults.Errors) - { - System.Console.WriteLine("Error: {0}", compErr); - } - - Assert.AreEqual(0, m_compilerResults.Errors.Count); + Assert.AreEqual(0, compilerResults.Errors.Count); } } } \ No newline at end of file