Skip to content

Commit

Permalink
(C# 3) Updated unit test deployment, ErrorManager initialization
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//depot/code/antlrcs/main/": change = 8950]
  • Loading branch information
sharwell committed Jul 30, 2011
1 parent e47d8a6 commit cdcf0ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
18 changes: 15 additions & 3 deletions Antlr3.Test/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ namespace AntlrUnitTests
using System.Linq;
using Antlr.Runtime;
using Antlr.Runtime.JavaExtensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Antlr3.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using AntlrTool = Antlr3.AntlrTool;
using BindingFlags = System.Reflection.BindingFlags;
using CultureInfo = System.Globalization.CultureInfo;
using Debugger = System.Diagnostics.Debugger;
using Directory = System.IO.Directory;
using ErrorManager = Antlr3.Tool.ErrorManager;
Expand All @@ -61,6 +62,15 @@ namespace AntlrUnitTests
using StringTemplateGroup = Antlr4.StringTemplate.TemplateGroup;

[TestClass]
#if DEBUG
[DeploymentItem(@"bin\Debug\Codegen\", "Codegen")]
[DeploymentItem(@"bin\Debug\Targets\", "Targets")]
[DeploymentItem(@"bin\Debug\Tool\", "Tool")]
#else
[DeploymentItem(@"bin\Release\Codegen\", "Codegen")]
[DeploymentItem(@"bin\Release\Targets\", "Targets")]
[DeploymentItem(@"bin\Release\Tool\", "Tool")]
#endif
public abstract class BaseTest
{
public readonly string jikes = null;
Expand Down Expand Up @@ -111,6 +121,8 @@ public void setUp()
// new output dir for each test
tmpdir = Path.GetFullPath( Path.Combine( Path.GetTempPath(), "antlr-" + currentTimeMillis() ) );

ErrorManager.SetLocale(CultureInfo.GetCultureInfo("en-us"));
ErrorManager.SetFormat("antlr");
ErrorManager.ResetErrorState();
StringTemplateGroup.DefaultGroup = new StringTemplateGroup();

Expand Down Expand Up @@ -929,7 +941,7 @@ protected void writeTreeTestFile( string parserName,
{
createParserST =
new StringTemplate(
" $parserName$ parser = new $parserName$(tokens);\n" );
" <parserName> parser = new <parserName>(tokens);\n" );
}
outputFileST.SetAttribute( "createParser", createParserST );
outputFileST.SetAttribute( "parserName", parserName );
Expand Down Expand Up @@ -1011,7 +1023,7 @@ protected void writeTemplateTestFile( string parserName,
"public class Test {\n" +
" static String templates =\n" +
" \"group test;\"+" +
" \"foo(x,y) ::= \\\"<x> <y>\\\"\";\n" +
" \"foo(x,y) ::= \\\"\\<x> \\<y>\\\"\";\n" +
" static StringTemplateGroup group =" +
" new StringTemplateGroup(new StringReader(templates)," +
" AngleBracketTemplateLexer.class);" +
Expand Down
13 changes: 11 additions & 2 deletions Antlr3/Tool/ErrorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public class ErrorState
*/
private static String[] idToMessageTemplateName = new String[MAX_MESSAGE_NUMBER + 1];

static ErrorManager()
{
InitIdToMessageNameMapping();
}

public static TraceListener ExternalListener
{
get;
Expand Down Expand Up @@ -394,8 +399,6 @@ public void InternalError(TemplateMessage msg)

internal static void Initialize()
{
InitIdToMessageNameMapping();

// it is inefficient to set the default locale here if another
// piece of code is going to set the locale, but that would
// require that a user call an init() function or something. I prefer
Expand All @@ -420,6 +423,9 @@ public static ITemplateErrorListener GetStringTemplateErrorListener()
*/
public static void SetLocale( CultureInfo locale )
{
if (ErrorManager.locale == locale)
return;

ErrorManager.locale = locale;
string language = locale.TwoLetterISOLanguageName;
string fileName = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(AntlrTool.ToolPathRoot, "Tool"), "Templates"), "messages"), "languages"), language + ".stg");
Expand Down Expand Up @@ -456,6 +462,9 @@ public static void SetLocale( CultureInfo locale )
*/
public static void SetFormat( String formatName )
{
if (ErrorManager.formatName == formatName)
return;

ErrorManager.formatName = formatName;
string fileName = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(AntlrTool.ToolPathRoot, "Tool"), "Templates"), "messages"), "formats"), formatName + ".stg");
format = new TemplateGroupFile(fileName);
Expand Down
6 changes: 1 addition & 5 deletions AntlrTestConfig.testrunconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<TestRunConfiguration name="AntlrTestConfig" id="ffdb4029-8f84-4bbb-9829-cc1e67c5715e" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>This is a default test run configuration for a local test run.</Description>
<CodeCoverage keyFile="Antlr3\Key.snk" />
<Deployment>
<DeploymentItem filename="bin\Debug\Codegen\" outputDirectory="Codegen" />
<DeploymentItem filename="bin\Debug\Targets\" outputDirectory="Targets" />
<DeploymentItem filename="bin\Debug\Tool\" outputDirectory="Tool" />
</Deployment>
<Deployment />
<Hosts>
<VSSDKTestHostRunConfig name="VS IDE" HiveKind="DevEnv" HiveName="9.0" IsRANU="false" xmlns="http://microsoft.com/schemas/VisualStudio/SDK/Tools/IdeHostAdapter/2006/06" />
<DeviceHostRunConfigData name="Smart Device" deviceId="AE1FD546-ECB8-4553-B0AA-53E129544859" deviceName="Pocket PC 2003 Device" platformId="3C41C503-53EF-4c2a-8DD4-A8217CAD115E" platformName="Pocket PC 2003" uiPlatformId="00000000-0000-0000-0000-000000000000" />
Expand Down

0 comments on commit cdcf0ec

Please sign in to comment.