Ver código fonte

Move CI to GitHub actions

Sébastien Ros 4 anos atrás
pai
commit
4d83ebd40b

+ 18 - 8
.github/workflows/build.yml

@@ -14,9 +14,9 @@ on:
     - 'readme.md'
 
 jobs:
-  build:
 
-    runs-on: ubuntu-latest
+  windows:
+    runs-on: windows-latest
     env:
         DOTNET_NOLOGO: true
         DOTNET_CLI_TELEMETRY_OPTOUT: 1
@@ -25,14 +25,24 @@ jobs:
     - name: Checkout source code
       uses: actions/checkout@v2
 
-    - name: Setup dotnet 2.1
-      uses: actions/setup-dotnet@v1
-      with:
-        dotnet-version: 2.1.*
-    - name: Setup dotnet 3.1
+    - name: Setup dotnet 5.0
       uses: actions/setup-dotnet@v1
       with:
-        dotnet-version: 3.1.*
+        dotnet-version: 5.0.*
+
+    - name: Test
+      run: dotnet test --configuration Release
+
+  linux:
+    runs-on: ubuntu-latest
+    env:
+        DOTNET_NOLOGO: true
+        DOTNET_CLI_TELEMETRY_OPTOUT: 1
+
+    steps:
+    - name: Checkout source code
+      uses: actions/checkout@v2
+
     - name: Setup dotnet 5.0
       uses: actions/setup-dotnet@v1
       with:

+ 0 - 10
.github/workflows/publish.yml

@@ -17,16 +17,6 @@ jobs:
     - name: Checkout source code
       uses: actions/checkout@v2
 
-    - name: Setup dotnet 2.1
-      uses: actions/setup-dotnet@v1
-      with:
-        dotnet-version: 2.1.*
-
-    - name: Setup dotnet 3.1
-      uses: actions/setup-dotnet@v1
-      with:
-        dotnet-version: 3.1.*
-
     - name: Setup dotnet 5.0
       uses: actions/setup-dotnet@v1
       with:

+ 3 - 2
Jint.Tests.CommonScripts/Jint.Tests.CommonScripts.csproj

@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFrameworks>net461;net5.0</TargetFrameworks>
+    <TargetFrameworks>net5.0</TargetFrameworks>
+    <!--<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>-->
     <IsPackable>false</IsPackable>
   </PropertyGroup>
   <ItemGroup>
@@ -10,7 +11,7 @@
     <ProjectReference Include="..\Jint\Jint.csproj" />
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit.analyzers" Version="0.10.0" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />

+ 27 - 27
Jint.Tests.CommonScripts/SunSpiderTests.cs

@@ -28,33 +28,33 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory(DisplayName = "Sunspider")]
-        [InlineData("3d-cube", "3d-cube.js")]
-        [InlineData("3d-morph", "3d-morph.js")]
-        [InlineData("3d-raytrace", "3d-raytrace.js")]
-        [InlineData("access-binary-trees", "access-binary-trees.js")]
-        [InlineData("access-fannkuch", "access-fannkuch.js")]
-        [InlineData("access-nbody", "access-nbody.js")]
-        [InlineData("access-nsieve", "access-nsieve.js")]
-        [InlineData("bitops-3bit-bits-in-byte", "bitops-3bit-bits-in-byte.js")]
-        [InlineData("bitops-bits-in-byte", "bitops-bits-in-byte.js")]
-        [InlineData("bitops-bitwise-and", "bitops-bitwise-and.js")]
-        [InlineData("bitops-nsieve-bits", "bitops-nsieve-bits.js")]
-        [InlineData("controlflow-recursive", "controlflow-recursive.js")]
-        [InlineData("crypto-aes", "crypto-aes.js")]
-        [InlineData("crypto-md5", "crypto-md5.js")]
-        [InlineData("crypto-sha1", "crypto-sha1.js")]
-        [InlineData("date-format-tofte", "date-format-tofte.js")]
-        [InlineData("date-format-xparb", "date-format-xparb.js")]
-        [InlineData("math-cordic", "math-cordic.js")]
-        [InlineData("math-partial-sums", "math-partial-sums.js")]
-        [InlineData("math-spectral-norm", "math-spectral-norm.js")]
-        [InlineData("regexp-dna", "regexp-dna.js")]
-        [InlineData("string-base64", "string-base64.js")]
-        [InlineData("string-fasta", "string-fasta.js")]
-        [InlineData("string-tagcloud", "string-tagcloud.js")]
-        [InlineData("string-unpack-code", "string-unpack-code.js")]
-        [InlineData("string-validate-input", "string-validate-input.js")]
-        public void RunScript(string name, string url)
+        [InlineData("3d-cube.js")]
+        [InlineData("3d-morph.js")]
+        [InlineData("3d-raytrace.js")]
+        [InlineData("access-binary-trees.js")]
+        [InlineData("access-fannkuch.js")]
+        [InlineData("access-nbody.js")]
+        [InlineData("access-nsieve.js")]
+        [InlineData("bitops-3bit-bits-in-byte.js")]
+        [InlineData("bitops-bits-in-byte.js")]
+        [InlineData("bitops-bitwise-and.js")]
+        [InlineData("bitops-nsieve-bits.js")]
+        [InlineData("controlflow-recursive.js")]
+        [InlineData("crypto-aes.js")]
+        [InlineData("crypto-md5.js")]
+        [InlineData("crypto-sha1.js")]
+        [InlineData("date-format-tofte.js")]
+        [InlineData("date-format-xparb.js")]
+        [InlineData("math-cordic.js")]
+        [InlineData("math-partial-sums.js")]
+        [InlineData("math-spectral-norm.js")]
+        [InlineData("regexp-dna.js")]
+        [InlineData("string-base64.js")]
+        [InlineData("string-fasta.js")]
+        [InlineData("string-tagcloud.js")]
+        [InlineData("string-unpack-code.js")]
+        [InlineData("string-validate-input.js")]
+        public void RunScript(string url)
         {
             var content = GetEmbeddedFile(url);
             RunTest(content);

+ 16 - 5
Jint.Tests.Ecma/EcmaTest.cs

@@ -156,16 +156,28 @@ namespace Jint.Tests.Ecma
         private static string staSource;
         private static readonly string BasePath;
         private static readonly List<SourceFile> _sourceFiles = new List<SourceFile>(10_000);
+        private static readonly TimeZoneInfo _pacificTimeZone;
 
         static EcmaTest()
         {
-            var assemblyPath = new Uri(typeof(EcmaTest).GetTypeInfo().Assembly.CodeBase).LocalPath;
+            try
+            {
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            }
+            catch (TimeZoneNotFoundException)
+            {
+                // https://stackoverflow.com/questions/47848111/how-should-i-fetch-timezoneinfo-in-a-platform-agnostic-way
+                // should be natively supported soon https://github.com/dotnet/runtime/issues/18644
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
+            }
+
+            var assemblyPath = new Uri(typeof(EcmaTest).GetTypeInfo().Assembly.Location).LocalPath;
             var assemblyDirectory = new FileInfo(assemblyPath).Directory;
             BasePath = assemblyDirectory.Parent.Parent.Parent.FullName;
 
             var localPath = assemblyDirectory.Parent.Parent.Parent.FullName;
 
-            var fixturesPath = Path.Combine(localPath, @"TestCases\alltests.json");
+            var fixturesPath = Path.Combine(localPath, "TestCases/alltests.json");
 
             var content = File.ReadAllText(fixturesPath);
             var doc = JArray.Parse(content);
@@ -196,15 +208,14 @@ namespace Jint.Tests.Ecma
             _lastError = null;
 
             //NOTE: The Date tests in test262 assume the local timezone is Pacific Standard Time
-            var pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
             var engine = new Engine(cfg => cfg
-                .LocalTimeZone(pacificTimeZone)
+                .LocalTimeZone(_pacificTimeZone)
             );
 
             // loading driver
             if (staSource == null)
             {
-                var driverFilename = Path.Combine(BasePath, "TestCases\\sta.js");
+                var driverFilename = Path.Combine(BasePath, "TestCases/sta.js");
                 staSource = File.ReadAllText(driverFilename);
             }
 

+ 2 - 1
Jint.Tests.Ecma/Jint.Tests.Ecma.csproj

@@ -1,13 +1,14 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>net5.0</TargetFramework>
+    <!--<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>-->
     <IsPackable>false</IsPackable>
   </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\Jint\Jint.csproj" />
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit.analyzers" Version="0.10.0" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />

+ 3 - 2
Jint.Tests.Test262/Jint.Tests.Test262.csproj

@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFrameworks>net461;net5.0</TargetFrameworks>
+    <TargetFrameworks>net5.0</TargetFrameworks>
+    <!--<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>-->
     <AssemblyOriginatorKeyFile>..\Jint\Jint.snk</AssemblyOriginatorKeyFile>
     <SignAssembly>true</SignAssembly>
     <IsPackable>false</IsPackable>
@@ -9,7 +10,7 @@
     <ProjectReference Include="..\Jint\Jint.csproj" />
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit.analyzers" Version="0.10.0" />

+ 13 - 3
Jint.Tests.Test262/Test262Test.cs

@@ -32,9 +32,18 @@ namespace Jint.Tests.Test262
         static Test262Test()
         {
             //NOTE: The Date tests in test262 assume the local timezone is Pacific Standard Time
-            _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            try
+            {
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            }
+            catch (TimeZoneNotFoundException)
+            {
+                // https://stackoverflow.com/questions/47848111/how-should-i-fetch-timezoneinfo-in-a-platform-agnostic-way
+                // should be natively supported soon https://github.com/dotnet/runtime/issues/18644
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
+            }
 
-            var assemblyPath = new Uri(typeof(Test262Test).GetTypeInfo().Assembly.CodeBase).LocalPath;
+            var assemblyPath = new Uri(typeof(Test262Test).GetTypeInfo().Assembly.Location).LocalPath;
             var assemblyDirectory = new FileInfo(assemblyPath).Directory;
 
             BasePath = assemblyDirectory.Parent.Parent.Parent.FullName;
@@ -167,7 +176,8 @@ namespace Jint.Tests.Test262
         {
             var results = new ConcurrentBag<object[]>();
             var fixturesPath = Path.Combine(BasePath, "test");
-            var searchPath = Path.Combine(fixturesPath, pathPrefix);
+            var segments = pathPrefix.Split('\\');
+            var searchPath = Path.Combine(fixturesPath, Path.Combine(segments));
             var files = Directory.GetFiles(searchPath, "*", SearchOption.AllDirectories);
 
             foreach (var file in files)

+ 3 - 2
Jint.Tests/Jint.Tests.csproj

@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFrameworks>net461;net5.0</TargetFrameworks>
+    <TargetFrameworks>net5.0</TargetFrameworks>
+    <TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>
     <AssemblyOriginatorKeyFile>..\Jint\Jint.snk</AssemblyOriginatorKeyFile>
     <SignAssembly>true</SignAssembly>
     <IsPackable>false</IsPackable>
@@ -16,7 +17,7 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="Flurl.Http.Signed" Version="3.0.0" />
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
     <PackageReference Include="MongoDB.Bson.signed" Version="2.11.2" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
     <PackageReference Include="xunit" Version="2.4.1" />

+ 1 - 1
Jint.Tests/Runtime/Domain/UuidConstructor.cs

@@ -32,7 +32,7 @@ namespace Jint.Tests.Runtime.Domain
 
         protected internal override ObjectInstance GetPrototypeOf() => _prototype;
 
-        internal ObjectInstance _prototype;
+        internal new ObjectInstance _prototype;
 
         public UuidPrototype PrototypeObject { get; private set; }
 

+ 1 - 1
Jint.Tests/Runtime/Domain/UuidInstance.cs

@@ -7,7 +7,7 @@ namespace Jint.Tests.Runtime.Domain
     {
         protected internal override ObjectInstance GetPrototypeOf() => _prototype;
 
-        internal ObjectInstance _prototype;
+        internal new ObjectInstance _prototype;
 
         public JsUuid PrimitiveValue { get; set; }
 

+ 48 - 13
Jint.Tests/Runtime/EngineTests.cs

@@ -20,6 +20,46 @@ namespace Jint.Tests.Runtime
         private readonly Engine _engine;
         private int countBreak = 0;
         private StepMode stepMode;
+        private static readonly TimeZoneInfo _pacificTimeZone;
+        private static readonly TimeZoneInfo _tongaTimeZone;
+        private static readonly TimeZoneInfo _easternTimeZone;
+
+
+        static EngineTests()
+        {
+            try
+            {
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            }
+            catch (TimeZoneNotFoundException)
+            {
+                // https://stackoverflow.com/questions/47848111/how-should-i-fetch-timezoneinfo-in-a-platform-agnostic-way
+                // should be natively supported soon https://github.com/dotnet/runtime/issues/18644
+                _pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
+            }
+
+            try
+            {
+                _tongaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tonga Standard Time");
+            }
+            catch (TimeZoneNotFoundException)
+            {
+                // https://stackoverflow.com/questions/47848111/how-should-i-fetch-timezoneinfo-in-a-platform-agnostic-way
+                // should be natively supported soon https://github.com/dotnet/runtime/issues/18644
+                _tongaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific/Tongatapu");
+            }
+
+            try
+            {
+                _easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time");
+            }
+            catch (TimeZoneNotFoundException)
+            {
+                // https://stackoverflow.com/questions/47848111/how-should-i-fetch-timezoneinfo-in-a-platform-agnostic-way
+                // should be natively supported soon https://github.com/dotnet/runtime/issues/18644
+                _easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
+            }
+        }
 
         public EngineTests(ITestOutputHelper output)
         {
@@ -1297,7 +1337,7 @@ myarr[0](0);
         [Fact]
         public void UtcShouldUseUtc()
         {
-            var customTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
+            var customTimeZone = _tongaTimeZone;
 
             var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
 
@@ -1351,12 +1391,7 @@ myarr[0](0);
         [InlineData("1970-01-01T00:00:00.000-00:00")]
         public void ShouldParseAsUtc(string date)
         {
-#if NET451
-            const string customName = "Custom Time";
-            var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(7, 11, 0), customName, customName, customName, null, false);
-#else
-            var customTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tonga Standard Time");
-#endif
+            var customTimeZone = _tongaTimeZone;
             var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
 
             engine.SetValue("d", date);
@@ -1411,7 +1446,7 @@ myarr[0](0);
         [Theory, MemberData("TestDates")]
         public void TestDateToISOStringFormat(DateTime testDate)
         {
-            var customTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tonga Standard Time");
+            var customTimeZone = _pacificTimeZone;
 
             var engine = new Engine(ctx => ctx.LocalTimeZone(customTimeZone));
             var testDateTimeOffset = new DateTimeOffset(testDate, customTimeZone.GetUtcOffset(testDate));
@@ -1423,7 +1458,7 @@ myarr[0](0);
         [Theory, MemberData("TestDates")]
         public void TestDateToStringFormat(DateTime testDate)
         {
-            var customTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tonga Standard Time");
+            var customTimeZone = _pacificTimeZone;
 
             var engine = new Engine(ctx => ctx.LocalTimeZone(customTimeZone));
             var testDateTimeOffset = new DateTimeOffset(testDate, customTimeZone.GetUtcOffset(testDate));
@@ -1995,7 +2030,7 @@ var prep = function (fn) { fn(); };
         {
             // Forcing to PDT and FR for tests
             // var PDT = TimeZoneInfo.CreateCustomTimeZone("Pacific Daylight Time", new TimeSpan(-7, 0, 0), "Pacific Daylight Time", "Pacific Daylight Time");
-            var PDT = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            var PDT = _pacificTimeZone;
             var FR = new CultureInfo("fr-FR");
 
             var engine = new Engine(options => options.LocalTimeZone(PDT).Culture(FR))
@@ -2019,7 +2054,7 @@ var prep = function (fn) { fn(); };
         [Fact]
         public void DateShouldHonorTimezoneDaylightSavingRules()
         {
-            var EST = TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time");
+            var EST = _easternTimeZone;
             var engine = new Engine(options => options.LocalTimeZone(EST))
                 .SetValue("log", new Action<object>(Console.WriteLine))
                 .SetValue("assert", new Action<bool>(Assert.True))
@@ -2039,7 +2074,7 @@ var prep = function (fn) { fn(); };
         {
             // Forcing to PDT and FR for tests
             // var PDT = TimeZoneInfo.CreateCustomTimeZone("Pacific Daylight Time", new TimeSpan(-7, 0, 0), "Pacific Daylight Time", "Pacific Daylight Time");
-            var PDT = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            var PDT = _pacificTimeZone;
             var FR = new CultureInfo("fr-FR");
 
             new Engine(options => options.LocalTimeZone(PDT).Culture(FR))
@@ -2058,7 +2093,7 @@ var prep = function (fn) { fn(); };
         {
             // Forcing to PDT and FR for tests
             // var PDT = TimeZoneInfo.CreateCustomTimeZone("Pacific Daylight Time", new TimeSpan(-7, 0, 0), "Pacific Daylight Time", "Pacific Daylight Time");
-            var PDT = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+            var PDT = _pacificTimeZone;
             var FR = new CultureInfo("fr-FR");
 
             var engine = new Engine(options => options.LocalTimeZone(PDT).Culture(FR))