Vendor did a bit of work to preserve Sputnik's negative test cases in their existing format.

Still needs a bit of integration work into the test harness.

A number of Sputnik tests were written outside the context of a chapter's sections.  E.g.,
"Chapter 13" versus "Chapter 13, Section 1".  We now fake a section number ("13.0" for the
example above) for such cases when generating test case metadata.
This commit is contained in:
David Fugate 2011-04-08 13:29:16 -07:00
parent a1c34e8c0a
commit 24b2fcf78d
23 changed files with 310 additions and 37 deletions

View File

@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization.Formatters;
//this version has been modified to not split each #check into an individual test
@ -11,8 +14,12 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
{
public static class ES5TestScript
{
private static int fileCounter;
private static int fileCounter;
private static StringBuilder negativeTestCases;
private static string[] templates = {
ES5TestScript.GetTemplateFile(ResourceClass.BasicTemplate_FileName),
ES5TestScript.GetTemplateFile(ResourceClass.BasicPrereqTemplate_FileName),
ES5TestScript.GetTemplateFile(ResourceClass.BasicNegativeTemplate_FileName),
@ -43,6 +50,8 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
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 buildContent = string.Empty;
string destFullPath = string.Empty;
@ -52,7 +61,12 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
if (script.IsNegative)
{
templateIndex += 2;
if (!body.Contains("eval(")) body = WrapWithEval(body);
destDir = negativeDestDir;
//if (!body.Contains("eval(")) body = WrapWithEval(body);
}
else
{
destDir = positiveDestDir;
}
string template = templates[templateIndex];
Logger.WriteToLog("=====================================================================================");
@ -69,7 +83,8 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
// OutputFileCounter = OutputFileCounter + script.ConvertedFileCount;
// foreach (string check in script.Checks)
// {
string[] args = { script.Header,script.Id, script.SectionName, InsertStringEscapes(script.Description), script.ReplicationCode, body, preCondition };
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)
// {
@ -93,6 +108,29 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
writeTestCase.Close();
OutputFileCounter++;
}
if (script.IsNegative)
{
//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());
}
Logger.WriteToLog(destFullPath);
}
catch (ArgumentException ex)
@ -106,6 +144,55 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
// }
}
/// <summary>
/// Method to initialize the negative test record.
/// </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);
StreamWriter sw = new StreamWriter(fs);
sw.Write("var GlobalScopeTests =");
sw.Flush();
sw.Close();
fs.Close();
//negativeTestCases = new StringBuilder();
}
/// <summary>
/// Method to update the GlobalScope.js
/// </summary>
/// <param name="destination">Is the destination folder path</param>
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() + "};");
negativeTestCases.Clear();
}
private static string GetSerializedSputnikTestScript(SputnikTestScript sputnikTestScript)
{
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SputnikTestScript));
ser.WriteObject(stream, sputnikTestScript);
stream.Position = 0;
StreamReader sr = new StreamReader(stream);
return sr.ReadToEnd();
}
private static string WrapWithEval(string s)
{
return InsertStringEscapes(s, true);
@ -161,5 +248,25 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
string inputTemplatePath = ConfigurationManager.AppSettings[configSetting].ToString();
return (new StreamReader(inputTemplatePath)).ReadToEnd();
}
private static string GetPartialPath(string fullPath, int levelsRequired)
{
string remainingString = fullPath;
string[] partialPaths = new string[levelsRequired];
string finalPath = "GlobalScope";
for (int iterator = 0; iterator < levelsRequired; iterator++)
{
partialPaths[iterator] = remainingString.Substring(remainingString.LastIndexOf(@"\"));
remainingString = remainingString.Substring(0, remainingString.LastIndexOf(@"\"));
}
for (int iterator = partialPaths.Length - 1; iterator >= 0; iterator--)
{
finalPath += partialPaths[iterator];
}
//finalPath = finalPath.Replace(@"\/", "/");
return finalPath;
}
}
}

View File

@ -55,6 +55,7 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -101,6 +102,7 @@
<EmbeddedResource Include="ResourceClass.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ResourceClass.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
@ -125,6 +127,10 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Conformance\" />
<Folder Include="tests\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -12,7 +12,8 @@
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartWorkingDirectory>C:\Users\allenwb\Desktop\cvt262\prog\prog</StartWorkingDirectory>
<StartArguments>C:\Users\allenwb\Desktop\cvt262\sput9-8-2010\tests C:\Users\allenwb\Desktop\cvt262\result</StartArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartArguments>E:\test262-msft\test\suite\sputnik\conformance E:\test262-msft\test\suite\sputnik_new01</StartArguments>
</PropertyGroup>
</Project>

View File

@ -20,7 +20,7 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
source = args[0];
destination = args[1];
string root = "Conformance";
string root = "conformance";
int countInputFiles = 0;
try
@ -30,14 +30,17 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
if (Directory.Exists(source))
{
string[] filePaths = Directory.GetFiles(source, "*.js", SearchOption.AllDirectories);
ES5TestScript.InitGlobals(destination);
foreach (string filePath in filePaths)
{
SputnikTestScript testScript = new SputnikTestScript();
testScript.Load(filePath);
ES5TestScript.Save(testScript, root, destination);
testScript.Load(filePath);
ES5TestScript.Save(testScript, root, destination);
countInputFiles++;
}
ES5TestScript.UpdateGlobals(destination);
}
Logger.WriteToLog(ResourceClass.Total_Input_Files, countInputFiles.ToString());
Logger.WriteToLog(ResourceClass.Total_Output_Files, ES5TestScript.OutputFileCounter.ToString());

View File

@ -159,6 +159,15 @@ namespace Microsoft.Sputnik.Interop.ParserEngine {
}
}
/// <summary>
/// Looks up a localized string similar to assertion.
/// </summary>
internal static string LookFor_Assertion {
get {
return ResourceManager.GetString("LookFor_Assertion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to description.
/// </summary>

View File

@ -189,4 +189,7 @@
<data name="LookFor_NegativeStrictMode" xml:space="preserve">
<value>strict_mode_negative</value>
</data>
<data name="LookFor_Assertion" xml:space="preserve">
<value>assertion</value>
</data>
</root>

View File

@ -7,14 +7,17 @@ using System.Text.RegularExpressions;
using System.Xml;
using System.Configuration;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace Microsoft.Sputnik.Interop.ParserEngine
{
[DataContract]
public class SputnikTestScript
{
private string testScriptID = string.Empty;
private string testScriptSection = string.Empty;
private string testScriptDescription = string.Empty;
private string testScriptAssertion = string.Empty;
private string replicationCode = string.Empty;
private int actualFileConvertedCount = 0;
private bool negativeTest = false;
@ -26,11 +29,12 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
public string Header = string.Empty;
public string Body = string.Empty;
public string InitialComment = string.Empty;
/// <summary>
/// Gets or sets the ID.
/// </summary>
/// <value>The ID.</value>
/// <value>The ID.</value>
public string Id
{
get
@ -102,9 +106,12 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
actualFileConvertedCount = value;
}
}
/// <summary>
/// Gets or sets the testScriptDescription
/// </summary>
[DataMember]
public string Description
{
get
@ -118,6 +125,23 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
}
}
/// <summary>
/// Gets or sets the testScriptAssersion
/// </summary>
[DataMember]
public string Assertion
{
get
{
return testScriptAssertion;
}
set
{
if (value != null)
testScriptAssertion = value.Trim();
}
}
/// <summary>
/// Gets or sets the value for checkSections
/// </summary>
@ -271,6 +295,11 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
Match matchCommentTail = commentTailRegex.Match(fullFile);
this.Header = fullFile.Substring(0,matchCommentTail.Index+matchCommentTail.Length);
Regex csharpCommentRegx = new Regex("\\/\\*");
Match matchCSharpCommentHead = csharpCommentRegx.Match(this.Header);
this.InitialComment = this.Header.Substring(0, matchCSharpCommentHead.Index);
this.Body = fullFile.Substring(matchCommentTail.Index+matchCommentTail.Length);
// string commentFormat = ConfigurationManager.AppSettings[ResourceClass.CommentsRegexSettingKey].ToString();
@ -290,11 +319,15 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
string commentKey = arrComments[0].ToLower();
if (commentKey.Contains(ResourceClass.LookFor_Name))
{
this.Id = arrComments[arrComments.Length - 1].Trim(trimDelimit);
this.Id = GetRealId(arrComments[arrComments.Length - 1].Trim(trimDelimit));
}
if (commentKey.Contains(ResourceClass.LookFor_Section))
{
this.SectionName = arrComments[arrComments.Length - 1].Trim(trimDelimit);
this.SectionName = GetRealSectionName(arrComments[arrComments.Length - 1].Trim(trimDelimit));
}
if (commentKey.Contains(ResourceClass.LookFor_Assertion))
{
this.Assertion = arrComments[arrComments.Length - 1].Trim(trimDelimit);
}
if (commentKey.Contains(ResourceClass.LookFor_Description))
{
@ -340,16 +373,17 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
if (arrComments[0].Contains(ResourceClass.LookFor_Name))
{
this.Id = arrComments[arrComments.Length - 1];
this.Id = GetRealId(arrComments[arrComments.Length - 1]);
}
if (arrComments[0].Contains(ResourceClass.LookFor_Section))
{
this.SectionName = arrComments[arrComments.Length - 1];
this.SectionName = GetRealSectionName(arrComments[arrComments.Length - 1]);
}
if (arrComments[0].Contains(ResourceClass.LookFor_Description))
{
this.Description = arrComments[arrComments.Length - 1];
}
}
//string holdGlobalCode = matchGlobalCode.Value;
@ -362,6 +396,20 @@ namespace Microsoft.Sputnik.Interop.ParserEngine
this.PossibleChecksCount = checks.Count;
}
private static string GetRealId(string id)
{
Regex regx = new Regex("^ S([0-9]+)_");
return regx.Replace(id, " S$1.0_", 1);
}
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;
}
return regx.Replace(sectionName, " $1.0", 1);
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<formats>
<format id="1" sequence="1">\s*CHECK#[0-9]\r\n(.*(\r\n)?.)+</format>
</formats>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="LogFileDirectory" value="."/>
<add key="InputXMLPath" value=".\InputFormats.xml"/>
<add key="BasicInputTemplate" value=".\testTemplate.js"/>
<add key="BasicPrereqInputTemplate" value=".\testPrereqTemplate.js"/>
<add key="BasicNegativeInputTemplate" value=".\testNegativeTemplate.js"/>
<add key="BasicNegativePrereqInputTemplate" value=".\testNegativePrereqTemplate.js"/>
<add key="CommentsRegex" value="^@[a-zA-Z0-9]*(:\s*.*;{1})?$"/>
<add key="ChecksRegex" value=".\s*CHECK#[0-9].\s*"/>
<add key="GlobalCodeRegex" value="\*/[\r\n]*.*"/>
</appSettings>
</configuration>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="LogFileDirectory" value="."/>
<add key="InputXMLPath" value=".\InputFormats.xml"/>
<add key="BasicInputTemplate" value=".\testTemplate.js"/>
<add key="BasicPrereqInputTemplate" value=".\testPrereqTemplate.js"/>
<add key="BasicNegativeInputTemplate" value=".\testNegativeTemplate.js"/>
<add key="BasicNegativePrereqInputTemplate" value=".\testNegativePrereqTemplate.js"/>
<add key="CommentsRegex" value="^@[a-zA-Z0-9]*(:\s*.*;{1})?$"/>
<add key="ChecksRegex" value=".\s*CHECK#[0-9].\s*"/>
<add key="GlobalCodeRegex" value="\*/[\r\n]*.*"/>
</appSettings>
</configuration>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@ -0,0 +1,22 @@
{0}
// Converted for Test262 from original Sputnik source
ES5Harness.registerTest( {{
id: "{1}",
path: "{2}",
description: "{4}",
test: function testcase() {{
try {{
(function() {{
{5} {6} }})();
}} catch (__e__) {{return true /* failure is success */}};
return false /* but success is failure */
}},
precondition: function precond() {{
{7}
}}
}});

View File

@ -0,0 +1,4 @@
{8}
// Converted for Test262 from original Sputnik source
{5} {6}

View File

@ -0,0 +1,21 @@
{0}
// Converted for Test262 from original Sputnik source
ES5Harness.registerTest( {{
id: "{1}",
path: "{2}",
assertion: "{3}",
description: "{4}",
test: function testcase() {{
{5} {6}
}},
precondition: function precond() {{
{7}
}}
}});

View File

@ -0,0 +1,16 @@
{0}
// Converted for Test262 from original Sputnik source
ES5Harness.registerTest( {{
id: "{1}",
path: "{2}",
assertion: "{3}",
description: "{4}",
test: function testcase() {{
{5} {6}
}}
}});

View File

@ -6,17 +6,17 @@ id: "{1}",
path: "{2}",
description: "{3}",
description: "{4}",
test: function testcase() {{
try {{
(function() {{
{4} {5} }})();
{5} {6} }})();
}} catch (__e__) {{return true /* failure is success */}};
return false /* but success is failure */
}},
precondition: function precond() {{
{6}
{7}
}}
}});

View File

@ -1,18 +1,4 @@
{0}
{8}
// Converted for Test262 from original Sputnik source
ES5Harness.registerTest( {{
id: "{1}",
path: "{2}",
description: "{3}",
test: function testcase() {{
try {{
(function() {{
{4} {5} }})();
}} catch (__e__) {{return true /* failure is success */}};
return false /* but success is failure */
}}
}});
{5} {6}

View File

@ -6,14 +6,16 @@ id: "{1}",
path: "{2}",
description: "{3}",
assertion: "{3}",
description: "{4}",
test: function testcase() {{
{4} {5}
{5} {6}
}},
precondition: function precond() {{
{6}
{7}
}}
}});

View File

@ -6,9 +6,11 @@ id: "{1}",
path: "{2}",
description: "{3}",
assertion: "{3}",
description: "{4}",
test: function testcase() {{
{4} {5}
{5} {6}
}}
}});