Ejemplo n.º 1
0
        public void CheckDependencies_NonDllFile()
        {
            string inputFilename = "FromXmlFile_NonDllFile.xml";

            PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());
            //PackageDependency.CheckDependencies(inputFilename);
        }
Ejemplo n.º 2
0
        public void findDependencies_HardcodedDependencyNotInstalled()
        {
            var    inst          = new Installation(Directory.GetCurrentDirectory());
            var    pkgs          = inst.GetPackages();
            string inputXml      = @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Test3' xmlns ='http://opentap.io/schemas/package'>
  <Dependencies>
    <PackageDependency Package='NotInstalled' Version='Any'/>
  </Dependencies>
  <Files>
    <File Path='OpenTap.Package.UnitTests.dll'/>
  </Files>
</Package>
";
            string inputFilename = "test3.package.xml";

            File.WriteAllText(inputFilename, inputXml);

            try
            {
                PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());
                Assert.Fail("Missing dependency should have thrown an exception");
            }
            catch (Cli.ExitCodeException ex)
            {
                Assert.AreEqual((int)PackageCreateAction.ExitCodes.PackageDependencyError, ex.ExitCode);
            }
        }
Ejemplo n.º 3
0
        public void GetPluginName_Test()
        {
            string     inputFilename = "Packages/test2/package.xml";
            PackageDef pkg           = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            Assert.AreEqual("Test Step", pkg.Files?.FirstOrDefault()?.Plugins?.FirstOrDefault(p => p.Type == typeof(IfStep).FullName)?.BaseType);
            Assert.AreEqual(pkg.Files?.FirstOrDefault()?.Plugins.FirstOrDefault(p => p.Type == typeof(GenericScpiInstrument).FullName)?.BaseType, "Instrument");
        }
Ejemplo n.º 4
0
        public void FileRepositoryManagerTest()
        {
            string pkgContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Package Name=""BasicSteps"" xmlns=""http://keysight.com/schemas/TAP/Package"" OS=""Linux,Windows"">
 <Files>
  <File Path=""__BASICSTEPS_DLL__"">
    <UseVersion/>
  </File>
 </Files>
</Package>
".Replace("__BASICSTEPS_DLL__", Path.GetFileName(typeof(DelayStep).Assembly.Location));
            string pkgName    = "BasicSteps.xml";

            try
            {
                if (File.Exists(pkgName))
                {
                    File.Delete(pkgName);
                }
                File.WriteAllText(pkgName, pkgContent);
                string installDir = Path.GetDirectoryName(typeof(Package.PackageDef).Assembly.Location);
                var    pkg        = PackageDefExt.FromInputXml(pkgName, installDir);
                CollectionAssert.IsNotEmpty(pkg.Dependencies, "Package has no dependencies.");
                //Assert.AreEqual("OpenTAP", pkg.Dependencies.First().Name);
                pkg.CreatePackage("BasicSteps.TapPackage");

                List <IPackageRepository> repositories = new List <IPackageRepository>()
                {
                    new FilePackageRepository(installDir)
                };

                var packages = PackageRepositoryHelpers.GetPackagesFromAllRepos(repositories, new PackageSpecifier());
                CollectionAssert.IsNotEmpty(packages, "Repository does not list any packages.");
                Assert.IsTrue(packages.Any(p => p.Name == "BasicSteps"));


                var depVersion = pkg.Dependencies.First().Version;
                var version    = new SemanticVersion(depVersion.Major ?? 0, depVersion.Minor ?? 0, depVersion.Patch ?? 0, depVersion.PreRelease, "");
                var depName    = pkg.Dependencies.First().Name;
                packages = PackageRepositoryHelpers.GetPackagesFromAllRepos(repositories, new PackageSpecifier("BasicSteps"), new PackageIdentifier(depName, version, CpuArchitecture.Unspecified, null));
                CollectionAssert.IsNotEmpty(packages, "Repository does not list any compatible \"BasicSteps\" package.");
                Assert.IsTrue(packages.First().Name == "BasicSteps");
            }
            finally
            {
                if (File.Exists("BasicSteps.TapPackage"))
                {
                    File.Delete("BasicSteps.TapPackage");
                }
                if (File.Exists(pkgName))
                {
                    File.Delete(pkgName);
                }
            }
        }
Ejemplo n.º 5
0
        public void FromXmlFile_Test()
        {
            string inputFilename = "Packages/Package/package.xml";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            //Assert.AreEqual(inputFilename, pkg.FileName);

            CollectionAssert.IsNotEmpty(pkg.Files);
            Assert.AreEqual("OpenTap.dll", pkg.Files[0].FileName);
            Assert.AreEqual("Version", pkg.Files[0].GetCustomData <SetAssemblyInfoData>().FirstOrDefault().Attributes);

            CollectionAssert.IsNotEmpty(pkg.PackageActionExtensions);
            Assert.AreEqual("chmod", pkg.PackageActionExtensions[0].ExeFile);
            Assert.AreEqual("install", pkg.PackageActionExtensions[0].ActionName);
            Assert.AreEqual("+x tap", pkg.PackageActionExtensions[0].Arguments);

            CollectionAssert.IsNotEmpty(pkg.Dependencies);
        }
Ejemplo n.º 6
0
        public void findDependencies_SharedAssemblyReferenceInDependencies()
        {
            var    inst          = new Installation(Directory.GetCurrentDirectory());
            var    pkgs          = inst.GetPackages();
            string inputXml      = @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Test3' xmlns ='http://opentap.io/schemas/package'>
  <Files>
    <File Path='System.Reflection.Metadata.dll'/>
  </Files>
</Package>
";
            string inputFilename = "test3.package.xml";

            File.WriteAllText(inputFilename, inputXml);

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            // This package should not depend on the OpenTAP package, event though it contains System.Collections.Immutable.dll that System.Reflection.Metadata.dll from this package needs
            CollectionAssert.DoesNotContain(pkg.Dependencies.Select(d => d.Name), "OpenTAP");
        }
Ejemplo n.º 7
0
        public void findDependencies_SharedAssemblyReference()
        {
            var    inst          = new Installation(Directory.GetCurrentDirectory());
            var    pkgs          = inst.GetPackages();
            string inputXml      = @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Test3' xmlns ='http://opentap.io/schemas/package'>
  <Files>
    <File Path='OpenTap.Package.UnitTests.dll'/>
  </Files>
</Package>
";
            string inputFilename = "test3.package.xml";

            File.WriteAllText(inputFilename, inputXml);

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            // This package should depend on the OpenTAP package, since it contains OpenTAP.dll that OpenTap.Package.UnitTests.dll from this package needs
            CollectionAssert.Contains(pkg.Dependencies.Select(d => d.Name), "OpenTAP");
        }
Ejemplo n.º 8
0
        public void CreatePackage_NoObfuscation()
        {
            string inputFilename  = "Packages/Package/package.xml";
            string outputFilename = "Test.TapPlugin";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            try
            {
                pkg.CreatePackage(outputFilename);
                Assert.IsTrue(File.Exists(outputFilename));
            }
            finally
            {
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }
Ejemplo n.º 9
0
        public void CreatePackage_NoBinFiles()
        {
            File.Copy("Packages/Package_NoBinFiles/package.xml", "package_NoBinFiles.xml", true);
            string inputFilename  = "package_NoBinFiles.xml";
            string outputFilename = "Test.TapPackage";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            try
            {
                pkg.CreatePackage(outputFilename);
                Assert.IsTrue(File.Exists(outputFilename));
            }
            finally
            {
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }
Ejemplo n.º 10
0
        public void SaveManyTo_Simple()
        {
            string outputFileContent = "";

            PackageDef pkg  = PackageDefExt.FromInputXml("Packages/Package/package.xml", Directory.GetCurrentDirectory());
            PackageDef pkg1 = PackageDefExt.FromInputXml("Packages/test2/package.xml", Directory.GetCurrentDirectory());

            using (Stream str = new MemoryStream())
            {
                PackageDef.SaveManyTo(str, new List <PackageDef> {
                    pkg, pkg1
                });
                using (StreamReader reader = new StreamReader(str))
                {
                    reader.BaseStream.Seek(0, 0);
                    outputFileContent = reader.ReadToEnd();
                }
            }
            // check that the package now contains the new XML Schema URL
            StringAssert.Contains("xmlns=\"http://opentap.io/schemas/package\"", outputFileContent);
            Assert.AreEqual(2, Regex.Matches(outputFileContent, "xmlns").Count);
        }
Ejemplo n.º 11
0
        public void SaveTo_FromXmlFile_Dependency()
        {
            string inputXml      = @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Test3' xmlns ='http://opentap.io/schemas/package'>
  <Files>
    <File Path='OpenTap.Package.UnitTests.dll'>
        <UseVersion/>
    </File>
  </Files>
</Package>
";
            string inputFilename = "test3.package.xml";

            File.WriteAllText(inputFilename, inputXml);
            string outputFileContent = "";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            pkg.Files.First().IgnoredDependencies.AddRange(new[] { "abc", "test" });

            using (Stream str = new MemoryStream())
            {
                pkg.SaveTo(str);
                using (StreamReader reader = new StreamReader(str))
                {
                    reader.BaseStream.Seek(0, 0);
                    outputFileContent = reader.ReadToEnd();
                }
            }

            StringAssert.Contains("<PackageDependency Package=\"Test1\" Version=\"^1.2", outputFileContent);   // the Test2 package is a release version, so it should have 2 version numbers specified
            //StringAssert.Contains("<PackageDependency Package=\"Test2\" Version=\"1.2.3", outputFileContent); // the Test2 package is from an integration branch, so it should have 3 version numbers specified
            StringAssert.Contains("<PackageDependency Package=\"OpenTAP\"", outputFileContent);
            StringAssert.Contains("<IgnoreDependency>test</IgnoreDependency>", outputFileContent);

            // check that the dependency to XSeries is not there twice:
            Assert.IsFalse(Regex.IsMatch(outputFileContent, "(Test1).+\n.+(Test1)"));
        }
Ejemplo n.º 12
0
        public void findDependencies_HardcodedDependency()
        {
            var    inst          = new Installation(Directory.GetCurrentDirectory());
            var    pkgs          = inst.GetPackages();
            string inputXml      = @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Test3' xmlns ='http://opentap.io/schemas/package'>
  <Dependencies>
    <PackageDependency Package='OpenTAP' Version='Any'/>
  </Dependencies>
  <Files>
    <File Path='OpenTap.Package.UnitTests.dll'/>
  </Files>
</Package>
";
            string inputFilename = "test3.package.xml";

            File.WriteAllText(inputFilename, inputXml);

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            // This package should depend on the OpenTAP package only once.
            Assert.AreEqual(1, pkg.Dependencies.Count(d => d.Name == "OpenTAP"));
        }
Ejemplo n.º 13
0
        public void GitVersionDependency()
        {
            string inputFilename  = "Packages/GitVersionDependency/package.xml";
            string outputFilename = "GitversionDependency.TapPlugin";

            try
            {
                DummyPackageGenerator.InstallDummyPackage("DepName", new GitVersionCalulator(Directory.GetCurrentDirectory()).GetVersion().ToString());
                PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());
                pkg.CreatePackage(outputFilename);
                Assert.AreNotSame("$(GitVersion)", pkg.Dependencies.First().Version.ToString());
                VersionSpecifier versionSpecifier = new VersionSpecifier(pkg.Version, VersionMatchBehavior.Exact);

                Assert.AreEqual(pkg.Dependencies.FirstOrDefault(p => p.Name == "DepName").Version.ToString(), versionSpecifier.ToString());
            }
            finally
            {
                DummyPackageGenerator.UninstallDummyPackage("DepName");
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }