test262harness - Test262Harness 1.0.0-preview-20240216-1831

Test262 Harness for .NET

PM> Install-Package Test262Harness -Version 1.0.0-preview-20240216-1831 -Source https://www.myget.org/F/test262harness/api/v3/index.json

Copy to clipboard

> nuget.exe install Test262Harness -Version 1.0.0-preview-20240216-1831 -Source https://www.myget.org/F/test262harness/api/v3/index.json

Copy to clipboard

> dotnet add package Test262Harness --version 1.0.0-preview-20240216-1831 --source https://www.myget.org/F/test262harness/api/v3/index.json

Copy to clipboard
<PackageReference Include="Test262Harness" Version="1.0.0-preview-20240216-1831" />
Copy to clipboard
source https://www.myget.org/F/test262harness/api/v3/index.json

nuget Test262Harness  ~> 1.0.0-preview-20240216-1831
Copy to clipboard

> choco install Test262Harness --version 1.0.0-preview-20240216-1831 --source https://www.myget.org/F/test262harness/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "test262harness" -SourceLocation "https://www.myget.org/F/test262harness/api/v2"
Install-Module -Name "Test262Harness" -RequiredVersion "1.0.0-preview-20240216-1831" -Repository "test262harness" -AllowPreRelease
Copy to clipboard

Build NuGet NuGet MyGet

Test262-Harness-dotnet

This is a .NET test runner for Test262: ECMAScript Test Suite. It includes parsing and downloading logic for the test suite in package Test262Harness and test suite generator functionality via CLI too, Test262Harness.Console

Usage

Following projects are utilizing the test suite generation and show how to create NUnit based test suite that is being generated by downloaded snapshot from test262 GitHub repository.

  • Jint
    • Generates NUnit test suite to ensure compliance, suite can be run in parallel for faster feedback loop
  • esprima-dotnet
    • Generates NUnit test suite for parsing tests, also has custom console logic to compare allow-list.txt for problematic files and progress getting the to parse properly
  • acornima
    • Generates NUnit test suite for parsing tests

First you need need to install the required package to your test project, it should look similar to this:

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
    <PackageReference Include="NUnit" Version="4.0.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
    <PackageReference Include="Test262Harness" Version="1.0.0" />
  </ItemGroup>

Next you will need a configuration, similar to this (also check the configuration format section):

Test262Harness.settings.json example

{
  "SuiteGitSha": "28b31c0bf1960878abb36ab8597a0cae224a684d",
  "TargetPath": "./Generated",
  "Namespace": "My.Tests.Test262",
  "ExcludedFeatures": [
    "Atomics",
    "Temporal"
  ],
  "ExcludedFlags": [
    "async" 
  ],
  "ExcludedDirectories": [
    "annexB",
    "intl402"
  ],
  "ExcludedFiles": [
    "language/expressions/object/dstr-async-gen-meth-*",
    "language/expressions/assignment/fn-name-lhs-cover.js"
  ]
}

You need to create minimal test file stub to initialize your testing target, example from Jint project.

using System;
using System.IO;
using Esprima;
using Jint.Native;
using Jint.Native.ArrayBuffer;
using Jint.Runtime;
using Jint.Runtime.Descriptors;
using Jint.Runtime.Interop;
using Test262Harness;

namespace Jint.Tests.Test262;

public static partial class State
{
    /// <summary>
    /// Pre-compiled scripts for faster execution.
    /// </summary>
    public static readonly Dictionary<string, Script> Sources = new(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Handles initializing testing state.
/// </summary>
public partial class TestHarness
{
    private static partial Task InitializeCustomState()
    {
        foreach (var file in State.HarnessFiles)
        {
            var source = file.Program;
            State.Sources[Path.GetFileName(file.FileName)] = new JavaScriptParser(source, new ParserOptions(file.FileName)).ParseScript();
        }

        return Task.CompletedTask;
    }
}

public abstract partial class Test262Test
{
    private Engine BuildTestExecutor(Test262File file)
    {
        var engine = new Engine(cfg =>
        {
            var relativePath = Path.GetDirectoryName(file.FileName);
            cfg.EnableModules(new Test262ModuleLoader(State.Test262Stream.Options.FileSystem, relativePath));
        });

        if (file.Flags.Contains("raw"))
        {
            // nothing should be loaded
            return engine;
        }

        engine.Execute(State.Sources["assert.js"]);
        engine.Execute(State.Sources["sta.js"]);

        // initialize engine with Test262 expected host defined functions here
        // https://github.com/tc39/test262/blob/main/INTERPRETING.md#host-defined-functions

        engine.SetValue("print", new ClrFunction(engine, "print", (_, args) => TypeConverter.ToString(args.At(0))));
        // and more...

        // the cinded files that that are expected
        foreach (var include in file.Includes)
        {
            engine.Execute(State.Sources[include]);
        }

        return engine;
    }

    private static void ExecuteTest(Engine engine, Test262File file)
    {
        if (file.Type == ProgramType.Module)
        {
            engine.AddModule(file.FileName, builder => builder.AddSource(file.Program));
            engine.ImportModule(file.FileName);
        }
        else
        {
            engine.Execute(new JavaScriptParser(file.Program, new ParserOptions(file.FileName)).ParseScript());
        }
    }

    private partial bool ShouldThrow(Test262File testCase, bool strict)
    {
        return testCase.Negative;
    }
}

And also the CLI tool for generating the test suite, run this in you test project directory.

dotnet tool add Test262Harness.Console

When everything is installed, you should be able to run:

dotnet tool restore
dotnet test262 generate

Test262Harness.settings.json configuration file

List of most important things you can tweak in configuration file:

Key Default Description
SuiteGitSha none The GitHub commit to use when downloading the test suite
SuiteDirectory none Alternatively, you can point to local repository root
TargetPath none Where to generate the file to
Namespace Test262Harness.TestSuite Namespace for the generated source files
ExcludedFeatures [] Any feature you want to ignore
ExcludedFlags [] Any flag you want to ignore
ExcludedDirectories [] Any sub-directory you would like to ignore, for example annexB
ExcludedFiles [] List of specific files you would like to ignore

Exclusion maps to setting [Ignore] attribute in test suite.

Branches and releases

  • .NETFramework 6.0
    • SharpZipLib (>= 1.4.2)
    • YamlDotNet (>= 15.1.1)
    • Zio (>= 0.17.0)
    • ZString (>= 2.5.1)
  • .NETFramework 8.0
    • SharpZipLib (>= 1.4.2)
    • YamlDotNet (>= 15.1.1)
    • Zio (>= 0.17.0)
    • ZString (>= 2.5.1)
  • .NETStandard 2.0
    • SharpZipLib (>= 1.4.2)
    • System.Memory (>= 4.5.5)
    • YamlDotNet (>= 15.1.1)
    • Zio (>= 0.17.0)
    • ZString (>= 2.5.1)
  • .NETFramework 6.0: 6.0.0.0
  • .NETFramework 8.0: 8.0.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Marko Lahma

Authors

Marko Lahma

Project URL

https://github.com/lahma/test262-harness-dotnet

License

Unknown

Tags

test262,javascript,ecmascript,test,harness

Info

23 total downloads
1 downloads for version 1.0.0-preview-20240216-1831
Download (53.59 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.0-preview-20240216-1831 53.59 KB Fri, 16 Feb 2024 18:32:00 GMT 1
0.0.23-preview-20240216-1828 53.61 KB Fri, 16 Feb 2024 18:29:00 GMT 1
0.0.23-preview-20240216-1815 54.36 KB Fri, 16 Feb 2024 18:16:22 GMT 1
0.0.23-preview-20240216-1806 54.37 KB Fri, 16 Feb 2024 18:07:17 GMT 1
0.0.23-preview-20231228-1625 54.37 KB Thu, 28 Dec 2023 16:26:56 GMT 1
0.0.22-preview-20230810-1927 35.12 KB Thu, 10 Aug 2023 19:28:00 GMT 1
0.0.22-preview-20230810-0754 33.25 KB Thu, 10 Aug 2023 07:55:00 GMT 1
0.0.22-preview-20230507-1809 33.5 KB Sun, 07 May 2023 18:10:21 GMT 1
0.0.22-preview-20220925-0721 33.26 KB Sun, 25 Sep 2022 07:22:01 GMT 2
0.0.19-preview-20220918-0624 33.28 KB Sun, 18 Sep 2022 06:25:39 GMT 1
0.0.19-preview-20220807-0752 33.41 KB Sun, 07 Aug 2022 07:53:12 GMT 1
0.0.19-preview-20220807-0731 33.21 KB Sun, 07 Aug 2022 07:34:34 GMT 1
0.0.19-preview-20220807-0723 33.21 KB Sun, 07 Aug 2022 07:24:18 GMT 1
0.0.19-preview-20220730-1217 33.55 KB Sat, 30 Jul 2022 12:18:08 GMT 1
0.0.19-preview-20220730-1213 33.54 KB Sat, 30 Jul 2022 12:13:37 GMT 1
0.0.19-preview-20220730-0917 33.42 KB Sat, 30 Jul 2022 09:18:10 GMT 1
0.0.19-preview-20220730-0914 33.42 KB Sat, 30 Jul 2022 09:14:24 GMT 1
0.0.17-preview-20220730-0911 33.43 KB Sat, 30 Jul 2022 09:11:32 GMT 1
0.0.17-preview-20220526-1709 33.44 KB Thu, 26 May 2022 17:10:13 GMT 1
0.0.17-preview-20220526-1659 33.54 KB Thu, 26 May 2022 16:59:44 GMT 1
0.0.16 33.4 KB Thu, 26 May 2022 16:44:59 GMT 2