コード例 #1
0
        public void EqualsWorks()
        {
            var version1 = TheVersion.Parse("2.1");
            var version2 = TheVersion.Parse("2.1.0.0");

            Assert.AreEqual(version1, version2);

            version1 = TheVersion.Parse("2");
            version2 = TheVersion.Parse("2.0.0.0");
            Assert.AreEqual(version1, version2);

            version1 = TheVersion.Parse("2.1.3");
            version2 = TheVersion.Parse("2.1.3.0");
            Assert.AreEqual(version1, version2);

            version1 = TheVersion.Parse("2.1.3.alpha1");
            version2 = TheVersion.Parse("2.1.3.alpha1");
            Assert.AreEqual(version1, version2);

            version1 = TheVersion.Parse("2.alpha1.1.2");
            version2 = TheVersion.Parse("2.alpha1");
            Assert.AreNotEqual(version1, version2);

            version1 = TheVersion.Parse("2.1.alpha1.1");
            version2 = TheVersion.Parse("2.1.alpha1");
            Assert.AreNotEqual(version1, version2);
        }
コード例 #2
0
        public void FourPartsWithAlpha_IsValid()
        {
            var version = TheVersion.Parse("2.1.32.delta");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual(1, version.Minor);
            Assert.AreEqual(32, version.Patch);
            Assert.AreEqual(0, version.Build);
            Assert.AreEqual("delta", version.Special);
        }
コード例 #3
0
        public void TwoParts_IsValid()
        {
            var version = TheVersion.Parse("2.1");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual(1, version.Minor);
            Assert.AreEqual(0, version.Patch);
            Assert.AreEqual(0, version.Build);
            Assert.AreEqual(null, version.Special);
        }
コード例 #4
0
        public static IEnumerable <TestCaseData> ShouldParseVersionOutputs_TestCases()
        {
            yield return(new TestCaseData(
                             $"git-lfs/2.2.0 (GitHub; windows amd64; go 1.8.3; git a99f4b21){Environment.NewLine}",
                             TheVersion.Parse("2.2")).SetName("Windows GitLFS 2.2.0"));

            yield return(new TestCaseData(
                             $"git-lfs/2.2.0 (GitHub; darwin amd64; go 1.8.3){Environment.NewLine}",
                             TheVersion.Parse("2.2")).SetName("Mac GitLFS 2.2.0"));
        }
コード例 #5
0
        public static IEnumerable <TestCaseData> ShouldParseVersionOutputs_TestCases()
        {
            yield return(new TestCaseData(
                             $"git version 2.11.1.windows.1{Environment.NewLine}",
                             TheVersion.Parse("2.11.1.windows.1")).SetName("Windows 2.11.1"));

            yield return(new TestCaseData(
                             $"git version 2.12.2{Environment.NewLine}",
                             TheVersion.Parse("2.12.2")).SetName("Mac 2.12.2"));
        }
コード例 #6
0
        public void TwoPartsWithAlpha_IsValid()
        {
            var version = TheVersion.Parse("2.1alpha1");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual("1alpha1", version.Special);
            Assert.AreEqual(0, version.Minor);
            Assert.AreEqual(0, version.Patch);
            Assert.AreEqual(0, version.Build);
        }
コード例 #7
0
        public void FourParts_IsValid()
        {
            var version = TheVersion.Parse("2.1.32.5");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual(1, version.Minor);
            Assert.AreEqual(32, version.Patch);
            Assert.AreEqual(5, version.Build);
            Assert.AreEqual(null, version.Special);
        }
コード例 #8
0
        public void ParsingInvalidVersionStringsWorks()
        {
            var ret = TheVersion.Parse(null);

            Assert.AreEqual(TheVersion.Default, ret);
            ret = TheVersion.Parse("");
            Assert.AreEqual(TheVersion.Default, ret);
            ret = TheVersion.Parse("bla");
            Assert.AreEqual(TheVersion.Default, ret);
            ret = TheVersion.Parse("git version 2.11.1.windows.1");
            Assert.AreEqual(TheVersion.Default, ret);
        }
コード例 #9
0
        public void ComparisonWorks()
        {
            var version1 = TheVersion.Parse("2");
            var version2 = TheVersion.Parse("1");

            Assert.IsTrue(version1 > version2);

            version1 = TheVersion.Parse("1");
            version2 = TheVersion.Parse("1.1alpha1");
            Assert.IsTrue(version2 > version1);

            version1 = TheVersion.Parse("1.0");
            version2 = TheVersion.Parse("1.1alpha1");
            Assert.IsTrue(version1 < version2);

            version1 = TheVersion.Parse("1.1");
            version2 = TheVersion.Parse("1.1alpha1");
            Assert.IsTrue(version1 > version2);

            version1 = TheVersion.Parse("1.1");
            version2 = TheVersion.Parse("1.2.3alpha1");
            Assert.IsTrue(version1 < version2);
            Assert.IsTrue(version1 <= version2);

            version1 = TheVersion.Parse("1.2.3");
            version2 = TheVersion.Parse("1.2.3alpha1");
            Assert.IsTrue(version1 > version2);
            Assert.IsTrue(version1 >= version2);

            version1 = TheVersion.Parse("0.33.0-beta");
            version2 = TheVersion.Parse("0.32.0");
            Assert.IsTrue(version1 > version2);

            version1 = TheVersion.Parse("0.33.0");
            version2 = TheVersion.Parse("0.33.0-beta");
            Assert.IsTrue(version1 > version2);

            version1 = TheVersion.Parse("0.33.2");
            version2 = TheVersion.Parse("0.33.3-beta");
            Assert.IsTrue(version1 < version2);

            version1 = TheVersion.Parse("0.33.3-alpha");
            version2 = TheVersion.Parse("0.33.3-beta");
            Assert.IsTrue(version1 < version2);

            version1 = TheVersion.Parse("0.33.3");
            version2 = TheVersion.Parse("0.33.3-beta");
            Assert.IsTrue(version1 > version2);

            version1 = TheVersion.Parse("git version 2.11.1.windows.1");
            version2 = TheVersion.Parse("2.17.0.windows.1");
            Assert.IsTrue(version1 < version2);
        }
コード例 #10
0
        public void ShouldGetGitLfsVersion()
        {
            if (!SPath.IsWindows)
            {
                return;
            }

            using (var test = StartTest(TestData.TestRepoMasterCleanSynchronized))
            {
                var result   = test.GitClient.LfsVersion().RunSynchronously();
                var expected = TheVersion.Parse("2.6.1");
                result.Should().Be(expected);
            }
        }
コード例 #11
0
        public void ShouldGetGitLfsVersion()
        {
            if (!DefaultEnvironment.OnWindows)
            {
                return;
            }

            InitializePlatformAndEnvironment(TestRepoMasterCleanSynchronized);

            var result   = GitClient.LfsVersion().RunSynchronously();
            var expected = TheVersion.Parse("2.6.1");

            result.Should().Be(expected);
        }
コード例 #12
0
ファイル: GitClientTests.cs プロジェクト: nicknockname/Unity
        public void ShouldGetGitVersion()
        {
            if (!DefaultEnvironment.OnWindows)
            {
                return;
            }

            InitializePlatformAndEnvironment(TestRepoMasterCleanSynchronized);

            var result   = GitClient.Version().RunWithReturn(true);
            var expected = TheVersion.Parse("2.17.0");

            result.Major.Should().Be(expected.Major);
            result.Minor.Should().Be(expected.Minor);
            result.Patch.Should().Be(expected.Patch);
        }
コード例 #13
0
        public void ParsingStopsAtNonDigits()
        {
            var version = TheVersion.Parse("2.1.1beta2.3");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual(1, version.Minor);
            Assert.AreEqual(0, version.Patch);
            Assert.AreEqual(0, version.Build);
            Assert.AreEqual("1beta2.3", version.Special);

            version = TheVersion.Parse("2.3-beta-2.3-alpha.4");
            Assert.AreEqual(2, version.Major);
            Assert.AreEqual("3-beta-2.3-alpha.4", version.Special);
            Assert.AreEqual(0, version.Minor);
            Assert.AreEqual(0, version.Patch);
            Assert.AreEqual(0, version.Build);
        }
コード例 #14
0
ファイル: VersionTests.cs プロジェクト: ccf19881030/Unity-1
    public void ParsingStopsAtAlpha()
    {
        var version = TheVersion.Parse("2.1.1beta2.3");

        Assert.AreEqual(2, version.Major);
        Assert.AreEqual(1, version.Minor);
        Assert.AreEqual(0, version.Patch);
        Assert.AreEqual(0, version.Build);
        Assert.AreEqual("1beta2", version.Special);

        version = TheVersion.Parse("2.3beta2.3alpha.4");
        Assert.AreEqual(2, version.Major);
        Assert.AreEqual("3beta2", version.Special);
        Assert.AreEqual(0, version.Minor);
        Assert.AreEqual(0, version.Patch);
        Assert.AreEqual(0, version.Build);
    }
コード例 #15
0
 public static string GetInformationalVersion()
 {
     try
     {
         var attr = System.Attribute.GetCustomAttribute(typeof(ThisAssembly).Assembly, typeof(System.Reflection.AssemblyInformationalVersionAttribute)) as System.Reflection.AssemblyInformationalVersionAttribute;
         if (attr != null)
         {
             return(attr.InformationalVersion);
         }
         var basePath = Platform.Instance?.Environment.ExtensionInstallPath ?? NPath.Default;
         if (!basePath.IsInitialized)
         {
             return("0");
         }
         var version = basePath.Parent.Combine("version.json").ReadAllText().FromJson <VersionJson>(true);
         return(TheVersion.Parse(version.version).Version);
     }
     catch
     {
         return("0");
     }
 }
コード例 #16
0
        public void DetectingUnstableVersionsWorks()
        {
            var version = TheVersion.Parse("2");

            Assert.IsFalse(version.IsUnstable);

            version = TheVersion.Parse("1.2");
            Assert.IsFalse(version.IsUnstable);

            version = TheVersion.Parse("1.2.3");
            Assert.IsFalse(version.IsUnstable);

            version = TheVersion.Parse("1.2.3.4");
            Assert.IsFalse(version.IsUnstable);

            version = TheVersion.Parse("1.2alpha1");
            Assert.IsTrue(version.IsUnstable);

            version = TheVersion.Parse("1.2.3stuff");
            Assert.IsTrue(version.IsUnstable);

            version = TheVersion.Parse("1.2.3.4whatever");
            Assert.IsTrue(version.IsUnstable);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: nicknockname/Unity
        static int Main(string[] args)
        {
            LogHelper.LogAdapter = new ConsoleLogAdapter();

            int    retCode         = 0;
            string data            = null;
            string error           = null;
            int    sleepms         = 0;
            var    p               = new OptionSet();
            var    readInputToEof  = false;
            var    lines           = new List <string>();
            bool   runWebServer    = false;
            NPath  outfile         = NPath.Default;
            NPath  path            = NPath.Default;
            string releaseNotes    = null;
            int    webServerPort   = -1;
            bool   generateVersion = false;
            bool   generatePackage = false;
            string version         = null;
            string url             = null;
            string readVersion     = null;
            string msg             = null;


            p = p
                .Add("r=", (int v) => retCode                  = v)
                .Add("d=|data=", v => data                     = v)
                .Add("e=|error=", v => error                   = v)
                .Add("f=|file=", v => data                     = File.ReadAllText(v))
                .Add("ef=|errorFile=", v => error              = File.ReadAllText(v))
                .Add("s=|sleep=", (int v) => sleepms           = v)
                .Add("i|input", v => readInputToEof            = true)
                .Add("w|web", v => runWebServer                = true)
                .Add("port=", (int v) => webServerPort         = v)
                .Add("g|generateVersion", v => generateVersion = true)
                .Add("v=|version=", v => version               = v)
                .Add("p|gen-package", "Pass --version --url --path --md5 --rn --msg to generate a package", v => generatePackage = true)
                .Add("u=|url=", v => url = v)
                .Add("path=", v => path  = v.ToNPath())
                .Add("rn=", "Path to file with release notes", v => releaseNotes = v.ReadAllTextIfFileExists())
                .Add("msg=", "Path to file with message for package", v => msg   = v.ReadAllTextIfFileExists())
                .Add("readVersion=", v => readVersion = v)
                .Add("o=|outfile=", v => outfile      = v.ToNPath().MakeAbsolute())
                .Add("h|help", v => p.WriteOptionDescriptions(Console.Out));

            p.Parse(args);

            if (generatePackage)
            {
                var md5 = path.CalculateMD5();
                url += "/" + path.FileName;
                var package = new Package
                {
                    Message         = msg,
                    Md5             = md5,
                    ReleaseNotes    = releaseNotes,
                    ReleaseNotesUrl = null,
                    Url             = url,
                    Version         = TheVersion.Parse(version),
                };

                var json = package.ToJson(lowerCase: true, onlyPublic: false);
                if (outfile.IsInitialized)
                {
                    outfile.WriteAllText(json);
                }
                else
                {
                    Logger.Info(json);
                }
                return(0);
            }

            if (readVersion != null)
            {
                var json    = File.ReadAllText(readVersion);
                var package = json.FromJson <Package>(lowerCase: true, onlyPublic: false);
                Console.WriteLine(package);
                Console.WriteLine($"{package.Url} {package.Version}");
                return(0);
            }

            if (generateVersion)
            {
                Logger.Error($"Generating version json {version} to {(outfile.IsInitialized ? outfile : "console")}");
                var vv = TheVersion.Parse(version);
                url += $"/unity/releases/github-for-unity-{version}.unitypackage";
                var package = new Package {
                    Url = url, Version = vv
                };
                var json = package.ToJson(lowerCase: true, onlyPublic: false);
                if (outfile.IsInitialized)
                {
                    outfile.WriteAllText(json);
                }
                else
                {
                    Logger.Info(json);
                }
                return(0);
            }

            if (runWebServer)
            {
                if (webServerPort < 0)
                {
                    webServerPort = 50000;
                }
                RunWebServer(outfile, webServerPort);
                return(0);
            }

            if (readInputToEof)
            {
                string line;
                while ((line = Console.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            if (sleepms > 0)
            {
                Thread.Sleep(sleepms);
            }

            if (!String.IsNullOrEmpty(data))
            {
                Console.WriteLine(data);
            }
            else if (readInputToEof)
            {
                Console.WriteLine(String.Join(Environment.NewLine, lines.ToArray()));
            }

            if (!String.IsNullOrEmpty(error))
            {
                Console.Error.WriteLine(error);
            }

            return(retCode);
        }
コード例 #18
0
        static int Main(string[] args)
        {
            LogHelper.LogAdapter = new ConsoleLogAdapter();

            int    retCode         = 0;
            string data            = null;
            string error           = null;
            int    sleepms         = 0;
            var    p               = new OptionSet();
            var    readInputToEof  = false;
            var    lines           = new List <string>();
            bool   runWebServer    = false;
            SPath  outfile         = SPath.Default;
            SPath  path            = SPath.Default;
            string releaseNotes    = null;
            int    webServerPort   = -1;
            bool   generateVersion = false;
            bool   generatePackage = false;
            string version         = null;
            string url             = null;
            string readVersion     = null;
            string msg             = null;
            string host            = null;
            bool   runUsage        = false;

            var arguments = new List <string>(args);

            if (arguments.Contains("usage"))
            {
                runUsage = true;
                arguments.RemoveRange(0, 2);
            }

            p = p
                .Add("r=", (int v) => retCode       = v)
                .Add("d=|data=", v => data          = v)
                .Add("e=|error=", v => error        = v)
                .Add("f=|file=", v => data          = File.ReadAllText(v))
                .Add("ef=|errorFile=", v => error   = File.ReadAllText(v))
                .Add("sleep=", (int v) => sleepms   = v)
                .Add("i|input", v => readInputToEof = true)
                .Add("w|web", v => runWebServer     = true)
                .Add("p|port=", "Port", (int v) => webServerPort = v)
                .Add("g|generateVersion", v => generateVersion   = true)
                .Add("v=|version=", v => version = v)
                .Add("gen-package", "Pass --version --url --path --md5 --rn --msg to generate a package", v => generatePackage = true)
                .Add("u=|url=", v => url = v)
                .Add("path=", v => path  = v.ToSPath())
                .Add("rn=", "Path to file with release notes", v => releaseNotes = v.ReadAllTextIfFileExists())
                .Add("msg=", "Path to file with message for package", v => msg   = v.ReadAllTextIfFileExists())
                .Add("readVersion=", v => readVersion = v)
                .Add("o=|outfile=", v => outfile      = v.ToSPath().MakeAbsolute())
                .Add("h=", "Host", v => host          = v)
                .Add("help", v => p.WriteOptionDescriptions(Console.Out));

            var extra = p.Parse(arguments);

            if (runUsage)
            {
                extra.Remove("usage");
                p.Parse(extra);

                path = extra[extra.Count - 1].ToSPath();
                var server     = RunWebServer(webServerPort);
                var webRequest = (HttpWebRequest)WebRequest.Create(new UriString("http://localhost:" + webServerPort + "/api/usage/unity"));
                webRequest.Method = "POST";
                using (var sw = new StreamWriter(webRequest.GetRequestStream()))
                {
                    foreach (var line in path.ReadAllLines())
                    {
                        sw.WriteLine(line);
                    }
                }
                using (var webResponse = (HttpWebResponse)webRequest.GetResponseWithoutException())
                {
                    MemoryStream ms             = new MemoryStream();
                    var          responseLength = webResponse.ContentLength;
                    using (var sr = new StreamWriter(ms))
                        using (var responseStream = webResponse.GetResponseStream())
                        {
                            Utils.Copy(responseStream, ms, responseLength);
                        }
                    Console.WriteLine(Encoding.ASCII.GetString(ms.ToArray()));
                }

                server.Stop();
                return(0);
            }

            if (generatePackage)
            {
                var md5 = path.CalculateMD5();
                url += "/" + path.FileName;
                var package = new Package
                {
                    Message         = msg,
                    Md5             = md5,
                    ReleaseNotes    = releaseNotes,
                    ReleaseNotesUrl = null,
                    Url             = url,
                    Version         = TheVersion.Parse(version),
                };

                var json = package.ToJson(lowerCase: true, onlyPublic: false);
                if (outfile.IsInitialized)
                {
                    outfile.WriteAllText(json);
                }
                else
                {
                    Console.WriteLine(json);
                }
                return(0);
            }

            if (readVersion != null)
            {
                var json    = File.ReadAllText(readVersion);
                var package = json.FromJson <Package>(lowerCase: true, onlyPublic: false);
                Console.WriteLine(package);
                Console.WriteLine($"{package.Url} {package.Version}");
                return(0);
            }

            if (generateVersion)
            {
                Logger.Error($"Generating version json {version} to {(outfile.IsInitialized ? outfile : "console")}");
                var vv = TheVersion.Parse(version);
                url += $"/unity/releases/github-for-unity-{version}.unitypackage";
                var package = new Package {
                    Url = url, Version = vv
                };
                var json = package.ToJson(lowerCase: true, onlyPublic: false);
                if (outfile.IsInitialized)
                {
                    outfile.WriteAllText(json);
                }
                else
                {
                    Logger.Info(json);
                }
                return(0);
            }

            if (runWebServer)
            {
                if (webServerPort < 0)
                {
                    webServerPort = 50000;
                }
                RunWebServer(outfile, webServerPort);
                return(0);
            }

            if (readInputToEof)
            {
                string line;
                while ((line = Console.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            if (sleepms > 0)
            {
                Thread.Sleep(sleepms);
            }

            if (!String.IsNullOrEmpty(data))
            {
                Console.WriteLine(data);
            }
            else if (readInputToEof)
            {
                Console.WriteLine(String.Join(Environment.NewLine, lines.ToArray()));
            }

            if (!String.IsNullOrEmpty(error))
            {
                Console.Error.WriteLine(error);
            }

            return(retCode);
        }