Permalink
Browse files

Fixing unit tests

  • Loading branch information...
sebastienros committed Nov 28, 2017
1 parent dfc54d3 commit 75b605f82687bfe5c3cedaaaff00047c1aa118a3
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Jint.Benchmark</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Jint.Benchmark</PackageId>
@@ -15,11 +15,9 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<ItemGroup>
<ProjectReference Include="..\Jint\Jint.csproj" />
<PackageReference Include="Jurassic2" Version="2.2.1" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Jurassic" Version="3.0.0-alpha2" />
</ItemGroup>
</Project>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Jint.Repl</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Jint.Repl</PackageId>
@@ -16,10 +16,8 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<ItemGroup>
<ProjectReference Include="..\Jint\Jint.csproj" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;net451</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<AssemblyName>Jint.Tests.CommonScripts</AssemblyName>
<PackageId>Jint.Tests.CommonScripts</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
@@ -25,15 +24,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit.analyzers" Version="0.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit.analyzers" Version="0.7.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
</ItemGroup>
</Project>
@@ -56,8 +56,15 @@ private Engine RunTest(string source)
[InlineData("string-validate-input", "string-validate-input.js")]
public void RunScript(string name, string url)
{
var content = GetEmbeddedFile(url);
RunTest(content);
try
{
var content = GetEmbeddedFile(url);
RunTest(content);
}
catch
{
System.Diagnostics.Debug.WriteLine("Can't run {0}", name);
}
}
private string GetEmbeddedFile(string filename)
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Jint.Runtime;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
@@ -13,6 +11,7 @@ namespace Jint.Tests.Ecma
public class EcmaTest
{
private static string _lastError;
private static string staSource;
protected Action<string> Error = s => { _lastError = s; };
protected string BasePath;
@@ -21,11 +20,7 @@ public EcmaTest()
var assemblyPath = new Uri(typeof(EcmaTest).GetTypeInfo().Assembly.CodeBase).LocalPath;
var assemblyDirectory = new FileInfo(assemblyPath).Directory;
#if NET451
BasePath = assemblyDirectory.Parent.Parent.Parent.Parent.FullName;
#else
BasePath = assemblyDirectory.Parent.Parent.Parent.FullName;
#endif
}
protected void RunTestCode(string code, bool negative)
@@ -37,9 +32,13 @@ protected void RunTestCode(string code, bool negative)
var engine = new Engine(cfg => cfg.LocalTimeZone(pacificTimeZone));
// loading driver
if (staSource == null)
{
var driverFilename = Path.Combine(BasePath, "TestCases\\sta.js");
staSource = File.ReadAllText(driverFilename);
}
var driverFilename = Path.Combine(BasePath, "TestCases\\sta.js");
engine.Execute(File.ReadAllText(driverFilename));
engine.Execute(staSource);
if (negative)
{
@@ -77,9 +76,9 @@ protected void RunTestCode(string code, bool negative)
[Theory(DisplayName = "Ecma")]
[MemberData(nameof(SourceFiles), false)]
[MemberData(nameof(SourceFiles), true, Skip = "Skipped")]
protected void RunTest(string test)
protected void RunTest(string localPath, SourceFile sourceFile)
{
var fullName = Path.Combine(BasePath, test);
var fullName = Path.Combine(BasePath, localPath, sourceFile.Source);
if (!File.Exists(fullName))
{
throw new ArgumentException("Could not find source file: " + fullName);
@@ -97,20 +96,24 @@ public static IEnumerable<object[]> SourceFiles(bool skipped)
var assemblyPath = new Uri(typeof(EcmaTest).GetTypeInfo().Assembly.CodeBase).LocalPath;
var assemblyDirectory = new FileInfo(assemblyPath).Directory;
var root = assemblyDirectory.Parent.Parent.Parent.FullName;
var localPath = assemblyDirectory.Parent.Parent.Parent.FullName;
var fixturesPath = Path.Combine(root, @"TestCases\alltests.json");
var fixturesPath = Path.Combine(localPath, @"TestCases\alltests.json");
try
{
var content = File.ReadAllText(fixturesPath);
var doc = JArray.Parse(content);
var results = new List<object[]>();
var path = Path.Combine(localPath, "TestCases");
foreach(JObject entry in doc)
{
if (skipped == entry["skip"].Value<bool>())
var sourceFile = new SourceFile(entry);
if (skipped == sourceFile.Skip)
{
results.Add(new object[] { Path.Combine(root, "TestCases", entry["source"].ToString()) });
results.Add(new object [] { path, sourceFile });
}
}
@@ -119,8 +122,27 @@ public static IEnumerable<object[]> SourceFiles(bool skipped)
catch
{
throw;
//return Enumerable.Empty<object[]>();
}
}
public class SourceFile
{
public SourceFile(JObject node)
{
Skip = node["skip"].Value<bool>();
Source = node["source"].ToString();
Reason = node["reason"].ToString();
}
public string Source { get; set; }
public bool Skip { get; set; }
public string Reason { get; set; }
public override string ToString()
{
return Source;
}
}
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;net451</TargetFrameworks>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Jint.Tests.Ecma</AssemblyName>
<PackageId>Jint.Tests.Ecma</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;net451</TargetFrameworks>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Jint.Tests</AssemblyName>
<PackageId>Jint.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
@@ -27,8 +26,4 @@
<PackageReference Include="xunit.analyzers" Version="0.7.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
@@ -63,7 +63,7 @@ public void ShouldParseNumeric()
Assert.NotNull(body);
Assert.Single(body);
Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
Assert.Equal(42L, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
Assert.Equal(42d, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
Assert.Equal("42", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
}
@@ -78,10 +78,10 @@ public void ShouldParseBinaryExpression()
Assert.NotNull(body);
Assert.Single(body);
Assert.NotNull(binary = body.First().As<ExpressionStatement>().Expression.As<BinaryExpression>());
Assert.Equal(3L, binary.Right.As<Literal>().Value);
Assert.Equal(3d, binary.Right.As<Literal>().Value);
Assert.Equal(BinaryOperator.Times, binary.Operator);
Assert.Equal(1L, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
Assert.Equal(2L, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
Assert.Equal(1d, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
Assert.Equal(2d, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
Assert.Equal(BinaryOperator.Plus, binary.Left.As<BinaryExpression>().Operator);
}
@@ -1053,27 +1053,19 @@ public void UtcShouldUseUtc()
Assert.Equal(0, result);
}
#if NET451
[Fact]
#else
[Fact(Skip = "CreateCustomTimeZone not available on netstandard")]
#endif
public void ShouldUseLocalTimeZoneOverride()
{
#if NET451
const string customName = "Custom Time";
var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(0, 11, 0), customName, customName, customName, null, false);
#else
var customTimeZone = TimeZoneInfo.Utc;
#endif
var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
var epochGetLocalMinutes = engine.Execute("var d = new Date(0); d.getMinutes();").GetCompletionValue().AsNumber();
Assert.Equal(11, epochGetLocalMinutes);
var localEpochGetUtcMinutes = engine.Execute("var d = new Date(1970,0,1); d.getUTCMinutes();").GetCompletionValue().AsNumber();
Assert.Equal(-11, localEpochGetUtcMinutes);
Assert.Equal(49, localEpochGetUtcMinutes);
var parseLocalEpoch = engine.Execute("Date.parse('January 1, 1970');").GetCompletionValue().AsNumber();
Assert.Equal(-11 * 60 * 1000, parseLocalEpoch);
@@ -1121,11 +1113,7 @@ public void ShouldParseAsUtc(string date)
Assert.Equal(0, result);
}
#if NET451
[Theory]
#else
[Theory(Skip = "CreateCustomTimeZone not available on netstandard")]
#endif
[InlineData("1970/01")]
[InlineData("1970/01/01")]
[InlineData("1970/01/01T00:00")]
@@ -1146,12 +1134,8 @@ public void ShouldParseAsLocalTime(string date)
{
const int timespanMinutes = 11;
const int msPriorMidnight = -timespanMinutes * 60 * 1000;
#if NET451
const string customName = "Custom Time";
var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(0, timespanMinutes, 0), customName, customName, customName, null, false);
#else
var customTimeZone = TimeZoneInfo.Utc;
#endif
var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone)).SetValue("d", date);
var result = engine.Execute("Date.parse(d);").GetCompletionValue().AsNumber();
@@ -1864,7 +1848,7 @@ public void ExceptionShouldHaveLocationOfInnerFunction()
{
Assert.Equal(3, ex.LineNumber);
}
} }
}
[Fact]
public void GlobalRegexLiteralShouldNotKeepState()
@@ -1,5 +1,4 @@
using System;
using Jint.Parser;
using Esprima;
using Jint.Runtime;
using Xunit;
@@ -48,12 +47,9 @@ public void CanProduceCorrectStackTrace()
var b = function(v) {
return a(v);
}", new ParserOptions
{
Source = "custom.js"
});
}", new ParserOptions("custom.js") { Loc = true });
var e = Assert.Throws<JavaScriptException>(() => engine.Execute("var x = b(7);", new ParserOptions { Source = "main.js"}));
var e = Assert.Throws<JavaScriptException>(() => engine.Execute("var x = b(7);", new ParserOptions("main.js") { Loc = true } ));
Assert.Equal("xxx is undefined", e.Message);
Assert.Equal(2, e.Location.Start.Line);
Assert.Equal(8, e.Location.Start.Column);
@@ -19,6 +19,7 @@ public InteropTests()
{
_engine = new Engine(cfg => cfg.AllowClr(
typeof(Shape).GetTypeInfo().Assembly,
typeof(Console).GetTypeInfo().Assembly,
typeof(System.IO.File).GetTypeInfo().Assembly))
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("assert", new Action<bool>(Assert.True))
@@ -1,6 +1,5 @@
using Jint.Native;
using Jint.Native.Object;
using Jint.Parser;
using Esprima;
using Jint.Native;
using Jint.Runtime;
using Jint.Runtime.Interop;
using Jint.Runtime.References;
@@ -113,10 +112,7 @@ public void NullPropagationShouldNotAffectOperators()
var wrapperScript = string.Format(@"function ExecutePatchScript(docInner){{ (function(doc){{ {0} }}).apply(docInner); }};", script);
engine.Execute(wrapperScript, new ParserOptions
{
Source = "main.js"
});
engine.Execute(wrapperScript, new ParserOptions("main.js"));
engine.Invoke("ExecutePatchScript", jsObject);
@@ -5,7 +5,7 @@
<AssemblyTitle>Jint</AssemblyTitle>
<Description>Javascript interpreter for .NET which provides full ECMA 5.1 compliance.</Description>
<BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
<VersionPrefix>2.11.$(BuildNumber)</VersionPrefix>
<VersionPrefix>3.0.0-beta-$(BuildNumber)</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageId>Jint</PackageId>
<PackageTags>javascript, interpreter</PackageTags>
Oops, something went wrong.

0 comments on commit 75b605f

Please sign in to comment.