chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using OpenTap.Cli;
using System;
using System.Linq;
using System.Threading;
 
#pragma warning disable 1591 // TODO: Add XML Comments in this file, then remove this
namespace OpenTap.Package
{
 
    [Display("test", Group: "package", Description: "Run tests on one or more packages.")]
    public class PackageTestAction : PackageAction
    {
        [UnnamedCommandLineArgument("package(s)", Required = true, Description = "One or more packages to run tests for.")]
        public string[] Packages { get; set; }
 
        [CommandLineArgument("ignore-missing", Description = "Ignore packages in <package(s)> that are not currently installed.", ShortName = "i")]
        public bool IgnoreMissing { get; set; }
 
        public override int Execute(CancellationToken cancellationToken)
        {
            if (Packages == null)
                throw new Exception("No packages specified.");
 
            Packages = AutoCorrectPackageNames.Correct(Packages, Array.Empty<IPackageRepository>());
 
            var target = LockingPackageAction.GetLocalInstallationDir();
 
 
            Installer installer = new Installer(target, cancellationToken) {DoSleep = false};
            installer.ProgressUpdate += RaiseProgressUpdate;
            installer.Error += RaiseError;
 
            var installedPackages = new Installation(target).GetPackages();
 
            bool anyUnrecognizedPlugins = false;
            foreach (string pack in Packages)
            {
                PackageDef package = installedPackages.FirstOrDefault(p => p.Name == pack);
 
                if (package != null && package.PackageSource is InstalledPackageDefSource source)
                    installer.PackagePaths.Add(source.PackageDefFilePath);
                else if (!IgnoreMissing)
                {
                    log.Error("Package '{0}' is not installed", pack);
                    anyUnrecognizedPlugins = true;
                }
            }
 
            if (anyUnrecognizedPlugins)
                return (int) PackageExitCodes.InvalidPackageName;
 
            return installer.RunCommand("test", false, false);
        }
    }
}