A number of small improvements to Sputnik Test Converter:

- restructured the generated GlobalScope.js file such that the HTML test harness
  can import multiple such files without worrying about one blowing aways another's
  metadata
- inline with the last change, GlobalScope.js has been renamed to SputnikGlobalScope.js
  and generated directly to test\suite\*
- the path and ID properties for most entries in GlobalScope.js were incorrect.  That is,
  they were based on the metadata contained in the original Sputnik tests and not the
  new test262 directories and filenames
- generate global scope tests to test\suite\GlobalScope\* instead of
  test\suite\sputnik_converted\GlobalScope\*.  Going forward we need to move towards
  integrating all test sources into test262 directories (e.g., "GlobalScope"===good;
  "Sputnik\GlobalScope"===not-so-good)
- a few hacks to the sources (e.g., private vars to public vars) I'll fix in a refactoring
  later.  Just trying to get everything working first
This commit is contained in:
David Fugate 2011-04-19 10:15:02 -07:00
parent 24b2fcf78d
commit 06e62f878b
6 changed files with 90 additions and 182 deletions

View File

@ -14,8 +14,10 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
{
public static class ES5TestScript
{
private static int fileCounter;
private static int fileCounter;
private static StringBuilder negativeTestCases;
private static string globalScopeFileName = "\\SputnikGlobalScope.js";
private static string[] templates = {
@ -47,12 +49,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
/// <param name="destinationPath">Is the destination folder path</param>
public static void Save(SputnikTestScript script, string root, string destinationPath)
{
int indexOfRoot = script.FullPath.IndexOf(root, StringComparison.InvariantCulture);
string pathFromRoot = script.FullPath.Substring(indexOfRoot, script.FullPath.Length - indexOfRoot);
string destDir = Path.Combine(destinationPath, Path.GetDirectoryName(pathFromRoot));
string positiveDestDir = destDir.Replace("conformance", "");
string negativeDestDir = destDir.Replace("conformance", "GlobalScope");
// int fileCounter = 0;
string destDir = Path.Combine(destinationPath, Path.GetDirectoryName(script.pathFromRoot));
string buildContent = string.Empty;
string destFullPath = string.Empty;
string preCondition = string.IsNullOrEmpty(script.PreConditionCode) ? String.Empty : script.PreConditionCode;
@ -61,18 +58,10 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
if (script.IsNegative)
{
templateIndex += 2;
destDir = negativeDestDir;
//if (!body.Contains("eval(")) body = WrapWithEval(body);
}
else
{
destDir = positiveDestDir;
}
string template = templates[templateIndex];
Logger.WriteToLog("=====================================================================================");
Logger.WriteToLog("Source file={0}\n", script.FullPath);
// Logger.WriteToLog("Possible CHECK#s={0}\n", script.PossibleChecksCount.ToString());
// Logger.WriteToLog("Actual CHECK#s found={0}\n", script.Checks.Length.ToString());
Logger.WriteToLog("Destination(s)=");
if (script.Id == "")
{
@ -80,68 +69,59 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
Console.WriteLine();
}
// OutputFileCounter = OutputFileCounter + script.ConvertedFileCount;
// foreach (string check in script.Checks)
// {
string[] args = { script.Header, script.Id, script.SectionName, InsertStringEscapes(script.Assertion), InsertStringEscapes(script.Description), script.ReplicationCode, body, preCondition, script.InitialComment };
// ++fileCounter;
// if (script.Checks.Length > 1)
// {
// destFullPath = Path.Combine(destDir, string.Format(@"{0}-{1}.js", script.Id, fileCounter.ToString()));
// args[0] = args[0] + "-" + fileCounter.ToString();
// }
// else
// {
destFullPath = Path.Combine(destDir, string.Format(@"{0}.js", script.Id));
// }
try
string[] args = { script.Header, script.Id, script.SectionName, InsertStringEscapes(script.Assertion), InsertStringEscapes(script.Description), script.ReplicationCode, body, preCondition, script.InitialComment };
destFullPath = Path.Combine(destDir, string.Format(@"{0}.js", script.Id));
try
{
buildContent = string.Format(template, args);
string dirPath = Path.GetDirectoryName(destFullPath);
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
using (TextWriter writeTestCase = File.CreateText(destFullPath))
{
buildContent = string.Format(template, args);
string dirPath = Path.GetDirectoryName(destFullPath);
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
using (TextWriter writeTestCase = File.CreateText(destFullPath))
writeTestCase.WriteLine(buildContent);
writeTestCase.Flush();
writeTestCase.Close();
OutputFileCounter++;
}
if (script.IsNegative)
{
//Add details in stringbuilder.
string folderPath = GetPartialPath(destFullPath, 3);
StringBuilder sb = new StringBuilder();
sb.Append("GlobalScopeTests[\"GlobalScope/" + script.pathFromRoot.Replace("\\", "/") + "\"]");
sb.Append("=");
string s = GetSerializedSputnikTestScript(new SputnikTestScript()
{
Description = script.Description,
Assertion = script.Assertion,
});
sb.Append(s.Substring(0, s.LastIndexOf('}')) + ",\"negative\":\"syntax\"};");
if (negativeTestCases == null)
{
writeTestCase.WriteLine(buildContent);
writeTestCase.Flush();
writeTestCase.Close();
OutputFileCounter++;
negativeTestCases = new StringBuilder();
}
if (script.IsNegative)
else
{
//Add details in stringbuilder.
string folderPath = GetPartialPath(destFullPath,3);
StringBuilder sb = new StringBuilder();
sb.Append("\"GlobalScope/" + script.SectionName + "/" + script.Id + ".js\"");
//negativeTestCases.Append("\""+folderPath+"\"");
sb.Append(":");
string s = GetSerializedSputnikTestScript(new SputnikTestScript()
{
Description = script.Description,
Assertion = script.Assertion,
});
sb.Append(s.Substring(0, s.LastIndexOf('}')) + ",\"negative\":\"syntax\"}");
if (negativeTestCases == null)
negativeTestCases = new StringBuilder();
else
negativeTestCases.Append(",");
negativeTestCases.Append(sb.ToString());
negativeTestCases.Append("\n");
}
negativeTestCases.Append(sb.ToString());
}
Logger.WriteToLog(destFullPath);
}
catch (ArgumentException ex)
{
Logger.WriteToLog(ResourceClass.IOException, ex.Message);
}
catch (IOException ex)
{
Logger.WriteToLog(ResourceClass.IOException, ex.Message);
}
// }
Logger.WriteToLog(destFullPath);
}
catch (ArgumentException ex)
{
Logger.WriteToLog(ResourceClass.IOException, ex.Message);
}
catch (IOException ex)
{
Logger.WriteToLog(ResourceClass.IOException, ex.Message);
}
// }
}
/// <summary>
@ -149,20 +129,18 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
/// </summary>
/// <param name="destination">Is the destination folder path</param>
public static void InitGlobals(string destination)
{
{
//Insert inital var name in Globals.js file.
//FileStream fs = new FileStream("c:\\ecmascript\\GlobalScope.js", FileMode.Create, FileAccess.Write);
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination);
}
FileStream fs = new FileStream(destination + "\\GlobalScope.js", FileMode.Create, FileAccess.Write);
FileStream fs = new FileStream(destination.Remove(destination.LastIndexOf("\\")) + globalScopeFileName, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write("var GlobalScopeTests =");
sw.Write("this.GlobalScopeTests = this.GlobalScopeTests || new Array();\n");
sw.Flush();
sw.Close();
fs.Close();
//negativeTestCases = new StringBuilder();
}
/// <summary>
@ -172,11 +150,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
public static void UpdateGlobals(string destination)
{
//Replace the last comma by closing curly brace and semi-colon.
//negativeTestCases.Replace(",", "};", negativeTestCases.Length - 2, 2);
//negativeTestCases.Append(";");
//File.AppendAllText("c:\\temp\\GlobalScope.js", "{"+negativeTestCases.ToString()+"};");
File.AppendAllText(destination +"\\GlobalScope.js", "{" + negativeTestCases.ToString() + "};");
File.AppendAllText(destination.Remove(destination.LastIndexOf("\\")) + globalScopeFileName, negativeTestCases.ToString());
negativeTestCases.Clear();
}
@ -191,16 +165,16 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
StreamReader sr = new StreamReader(stream);
return sr.ReadToEnd();
}
}
private static string WrapWithEval(string s)
{
return InsertStringEscapes(s, true);
}
private static string InsertStringEscapes(string s, bool wrapWithEval=false)
private static string InsertStringEscapes(string s, bool wrapWithEval = false)
{
StringReader rdr=new StringReader(s);
StringReader rdr = new StringReader(s);
StringWriter wtr = new StringWriter();
int intChar;
char nextChar;
@ -246,7 +220,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
private static string GetTemplateFile(string configSetting)
{
string inputTemplatePath = ConfigurationManager.AppSettings[configSetting].ToString();
return (new StreamReader(inputTemplatePath)).ReadToEnd();
return (new StreamReader(inputTemplatePath)).ReadToEnd();
}
private static string GetPartialPath(string fullPath, int levelsRequired)
@ -263,9 +237,8 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
for (int iterator = partialPaths.Length - 1; iterator >= 0; iterator--)
{
finalPath += partialPaths[iterator];
finalPath += partialPaths[iterator];
}
//finalPath = finalPath.Replace(@"\/", "/");
return finalPath;
}
}

View File

@ -12,6 +12,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
{
string source = string.Empty;
string destination = string.Empty;
string globalScopeDestination = string.Empty;
if (args == null || args.Length < 2)
{
@ -19,28 +20,41 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
}
source = args[0];
destination = args[1];
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination);
}
globalScopeDestination = destination.Remove(destination.LastIndexOf("\\") + 1) + "GlobalScope";
string root = "conformance";
int countInputFiles = 0;
try
{
Logger.WriteToLog("Start Time : {0}", DateTime.Now.ToString());
if (Directory.Exists(source))
{
string[] filePaths = Directory.GetFiles(source, "*.js", SearchOption.AllDirectories);
ES5TestScript.InitGlobals(destination);
ES5TestScript.InitGlobals(globalScopeDestination);
foreach (string filePath in filePaths)
{
SputnikTestScript testScript = new SputnikTestScript();
testScript.Load(filePath);
ES5TestScript.Save(testScript, root, destination);
testScript.Load(filePath, root);
if (testScript.IsNegative)
{
ES5TestScript.Save(testScript, root, globalScopeDestination);
}
else
{
ES5TestScript.Save(testScript, root, destination);
}
countInputFiles++;
}
ES5TestScript.UpdateGlobals(destination);
ES5TestScript.UpdateGlobals(globalScopeDestination);
}
Logger.WriteToLog(ResourceClass.Total_Input_Files, countInputFiles.ToString());
Logger.WriteToLog(ResourceClass.Total_Output_Files, ES5TestScript.OutputFileCounter.ToString());

View File

@ -20,7 +20,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
private string testScriptAssertion = string.Empty;
private string replicationCode = string.Empty;
private int actualFileConvertedCount = 0;
private bool negativeTest = false;
public bool negativeTest = false;
private bool strictModeNegativeTest = false;
private const string xmlNode = "format";
private const string xmlAttribute = "sequence";
@ -30,6 +30,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
public string Header = string.Empty;
public string Body = string.Empty;
public string InitialComment = string.Empty;
public string pathFromRoot = string.Empty;
/// <summary>
/// Gets or sets the ID.
@ -235,7 +236,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
/// Loads the sputnik testscript file and extracts the required details from it
/// </summary>
/// <param name="filePath">Path to the source file</param>
public void Load(string filePath)
public void Load(string filePath, string root)
{
string[] regexTrimDelimiter = { "\n","\r"};
String fullFile = string.Empty;
@ -245,39 +246,11 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
fullFile = txtReader.ReadToEnd();
}
this.FullPath = filePath;
// ReadTestCaseEpilogue(fullFile);
int indexOfRoot = this.FullPath.IndexOf(root, StringComparison.InvariantCulture) + root.Length + 1;
this.pathFromRoot = this.FullPath.Substring(indexOfRoot, this.FullPath.Length - indexOfRoot);
ReadSimpleTestCase(fullFile);
/*
//read input format from xml
foreach (KeyValuePair<string, string> regxFormat in testScriptFormats)
{
Regex regxCode = new Regex(regxFormat.Value.Trim(), RegexOptions.IgnoreCase);
MatchCollection matchCode = regxCode.Matches(fullFile);
this.checkSections = new string[matchCode.Count];
int counter = 0;
//Read the code section
foreach (Match codeSection in matchCode)
{
if (codeSection.Value.ToLower().Contains("check"))
{
this.checkSections[counter] = codeSection.Value.Remove(0, codeSection.Value.IndexOf("\r"));
}
else
{
this.checkSections[counter] = codeSection.Value;
}
counter++;
}
if (checkSections.Length > 0)
{
this.actualFileConvertedCount++;
break;
}
}
*/
}
/// <summary>
@ -302,15 +275,10 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
this.Body = fullFile.Substring(matchCommentTail.Index+matchCommentTail.Length);
// string commentFormat = ConfigurationManager.AppSettings[ResourceClass.CommentsRegexSettingKey].ToString();
string commentFormat = "@[a-zA-Z0-9_]+(:\\s*[^\\r\\n]*)?;?\\s*(\\r|\\n)";
Regex regx = new Regex(commentFormat);
MatchCollection matchComments = regx.Matches(this.Header);
// string globalCode = ConfigurationManager.AppSettings[ResourceClass.GlobalCodeRegexKey].ToString();
// Regex gobalRegx = new Regex(globalCode);
// Match matchGlobalCode = gobalRegx.Match(fullFile);
foreach (Match comment in matchComments)
{
holdStr = comment.Value;
@ -319,11 +287,12 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
string commentKey = arrComments[0].ToLower();
if (commentKey.Contains(ResourceClass.LookFor_Name))
{
this.Id = GetRealId(arrComments[arrComments.Length - 1].Trim(trimDelimit));
this.Id = this.pathFromRoot.Substring(this.pathFromRoot.LastIndexOf("\\") + 1);
this.Id = GetRealId(this.Id.Remove(this.Id.Length - 3));
}
if (commentKey.Contains(ResourceClass.LookFor_Section))
{
this.SectionName = GetRealSectionName(arrComments[arrComments.Length - 1].Trim(trimDelimit));
this.SectionName = GetRealSectionName(this.pathFromRoot);
}
if (commentKey.Contains(ResourceClass.LookFor_Assertion))
{
@ -347,54 +316,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
this.PossibleChecksCount = 1;
}
/// <summary>
/// Reads the Epilogue from the sputnik testscript file
/// </summary>
/// <param name="fullFile">Input file content</param>
private void ReadTestCaseEpilogue(string fullFile)
{
char[] delimiter = { ':' };
char[] trimDelimit = { ';' };
string holdStr = string.Empty;
string[] arrComments;
string commentFormat = ConfigurationManager.AppSettings[ResourceClass.CommentsRegexSettingKey].ToString();
Regex regx = new Regex(commentFormat);
MatchCollection matchComments = regx.Matches(fullFile);
string globalCode = ConfigurationManager.AppSettings[ResourceClass.GlobalCodeRegexKey].ToString();
Regex gobalRegx = new Regex(globalCode);
Match matchGlobalCode = gobalRegx.Match(fullFile);
foreach (Match comment in matchComments)
{
holdStr = comment.Value.ToLower();
arrComments = holdStr.Trim(trimDelimit).Trim().Split(delimiter);
if (arrComments[0].Contains(ResourceClass.LookFor_Name))
{
this.Id = GetRealId(arrComments[arrComments.Length - 1]);
}
if (arrComments[0].Contains(ResourceClass.LookFor_Section))
{
this.SectionName = GetRealSectionName(arrComments[arrComments.Length - 1]);
}
if (arrComments[0].Contains(ResourceClass.LookFor_Description))
{
this.Description = arrComments[arrComments.Length - 1];
}
}
//string holdGlobalCode = matchGlobalCode.Value;
//if(holdGlobalCode.StartsWith("*/"))
//ReplicationCode = holdGlobalCode.Remove(0, holdGlobalCode.IndexOf("*/")).Trim();
//Get a hint on possible CHECK#'s contained in the file.
regx = new Regex(ConfigurationManager.AppSettings[ResourceClass.ChecksRegexSettingKey].ToString());
MatchCollection checks = regx.Matches(fullFile);
this.PossibleChecksCount = checks.Count;
}
private static string GetRealId(string id)
{
@ -403,7 +325,6 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
}
private static string GetRealSectionName(string sectionName)
{
//Regex regx = new Regex("/S([0-9]+)_([^/]+)$");
Regex regx = new Regex("^ ([0-9]+)$");
if (! regx.IsMatch(sectionName)) {
return sectionName;