Test (closed) patches for errors

Request

Feature request is for a way to select a folder and have gamma editor open and check every patch for errors. Leave the patches that have errors open as well as the error browser so I can fix them.

Usecase

Current need is I’m developing a library (VL.PolyTools) and as it expands I need to do minor recategorizations that I know will cause errors. And of course I occasionally cause inadvertent errors.

Now there are a lot of helppatches and it would be convenient if I could run a command to check them all for errors rather than manually opening each one.

Stretch goal

Integration with VL.TestFramework? Make such a test for ‘gamma editor’ errors a default test?

3 Likes

I think something like that is already running on the build server:

http://teamcity.vvvv.org/buildConfiguration/vvvv_gamma_Build20225/37512?buildTab=tests&name=DocumentHasNoError

1 Like

This is doable with the VL.TestFramework package. It needs a little bit of C# code where you define what patches should be looked at / whether or not to run their entry points.

Here would be the relevant commands to setup such a test project:

cd your\project
mkdir tests
cd tests
dotnet new nunit
dotnet add package VL.TestFramework

Now modify the generated UnitTest1.cs file like this:

using VL.TestFramework;

namespace tests;

public class Tests
{
    // The directory of this dll
    public static string ThisDirectory => Path.GetDirectoryName(typeof(Tests).Assembly.Location)!;
    // Assuming the default output location the root dir of our package should be
    public static string PackageDirectory => Path.GetFullPath(Path.Combine(ThisDirectory, "..", "..", "..", ".."));
    // Path to our help patches
    public static string HelpDirectory => Path.Combine(PackageDirectory, "help");
    // We pass this one as a search path to vvvv
    public static string PackageRepository => Path.GetFullPath(Path.Combine(PackageDirectory, ".."));

    TestEnvironment? testEnvironment;

    // Watch out: Don't use async Task here. NUnit keeps a synchronization context per async method,
    // subsequent calls to the session therefor fail with the exception that the context had been shut down.
    // See https://github.com/nunit/nunit/issues/3500
    [OneTimeSetUp]
    public void Setup()
    {
        // Sadly the auto version selection with the 5.2 release doesn't work, so we need to specify the build id and version manually so the download works
        var vvvvExePath = Task.Run(() => TestEnvironmentLoader.DownloadEntryAssemblyAsync(37342, "5.2"));
        // You might want to pass in the proper search path here so your package is found
        testEnvironment = TestEnvironmentLoader.Load(vvvvExePath.Result!, searchPaths: new [] { PackageRepository });
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        testEnvironment?.Dispose();
        testEnvironment = null;
    }

    [TestCaseSource(nameof(GetHelpPatches))]
    public async Task IsntRed(string filePath)
    {
        // Note: If runEntryPoint = true, we need to add <UseWindowsForms>true</UseWindowsForm> to the tests.csproj file, otherwise we get a weired crash on startup
        await testEnvironment!.LoadAndTestAsync(filePath, runEntryPoint: false);
    }

    public static IEnumerable<string> GetHelpPatches()
    {
        // Here you would specify what patches should be looked at
        return Directory.EnumerateFiles(HelpDirectory, "*.vl");
    }
}

You can now run the tests with

dotnet test

We use this method internally to test our patches. Whether or not this will also work as a github action I don’t know - we run it on a private machine using teamcity.

Attached you find a working test project for reference
MyLib.zip (4.6 KB)

2 Likes