From 3cbdf3bfe0b7b3f5d41472ec7e7a9c9d0db32edc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 18 Jun 2014 23:04:31 +0100 Subject: refactor: Simplify compilation result tests by factoring out common code. --- .../Shared/CodeTools/Tests/CompilerTest.cs | 116 ++++++++------------- 1 file changed, 45 insertions(+), 71 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs') 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 } } + private CompilerResults CompileScript( + string input, out Dictionary, KeyValuePair> positionMap) + { + m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); + + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); + + output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); + // System.Console.WriteLine(output); + + positionMap = cg.PositionMap; + + CompilerResults 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); + // } + + return compilerResults; + } + /// /// Test that line number errors are resolved as expected when preceding code contains a jump. /// @@ -109,9 +139,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 = @"default + CompilerResults compilerResults = CompileScript( +@"default { state_entry() { @@ -119,33 +150,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests @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); -// } +}", out positionMap); Assert.AreEqual( new KeyValuePair(7, 9), - positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); + positionMap[new KeyValuePair(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); } /// @@ -157,41 +166,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests { TestHelpers.InMethod(); - m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); + Dictionary, KeyValuePair> positionMap; - string input = @"default + CompilerResults compilerResults = CompileScript( +@"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; - - 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); - // } +}", 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); } -}"; - -// 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); - } +}", out positionMap); - Assert.AreEqual(0, m_compilerResults.Errors.Count); + Assert.AreEqual(0, compilerResults.Errors.Count); } } } \ No newline at end of file -- cgit v1.1