|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.MixedReality.Toolkit.Utilities.Editor; |
| 5 | +using NUnit.Framework; |
| 6 | +using System; |
| 7 | +using System.Collections; |
| 8 | +using System.Collections.Generic; |
| 9 | +using UnityEngine; |
| 10 | + |
| 11 | +namespace Microsoft.MixedReality.Toolkit.Tests.EditMode.Core.Utilities.Editor |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Tests that verify the correct behavior of the PackageManifestUpdater. |
| 15 | + /// </summary> |
| 16 | + public class PackageManifestUpdaterTests |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Verifies parsing of a properly formatted value returns the correct results. |
| 20 | + /// </summary> |
| 21 | + [Test] |
| 22 | + public void TryGetValidVersion() |
| 23 | + { |
| 24 | + Debug.Log("Try to get version from properly formatted version with no prerelease."); |
| 25 | + |
| 26 | + Version v; |
| 27 | + float f; |
| 28 | + |
| 29 | + bool success = PackageManifestUpdater.TryGetVersionComponents("17.27.43", out v, out f); |
| 30 | + Assert.IsTrue(success); |
| 31 | + Assert.AreEqual(v, new Version(17, 27, 43)); |
| 32 | + Assert.AreEqual(f, 0f); |
| 33 | + |
| 34 | + Debug.Log("Try to get version from properly formatted version with prerelease."); |
| 35 | + |
| 36 | + success = PackageManifestUpdater.TryGetVersionComponents("0.9.1-20200131.12", out v, out f); |
| 37 | + Assert.IsTrue(success); |
| 38 | + Assert.AreEqual(v, new Version(0, 9, 1)); |
| 39 | + Assert.AreEqual(f, float.Parse("20200131.12")); |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Verifies parsing of an improperly formatted string returns the correct failure results. |
| 44 | + /// </summary> |
| 45 | + [Test] |
| 46 | + public void TryGetInvalidVersion() |
| 47 | + { |
| 48 | + Debug.Log("Try to get version from improperly formatted version."); |
| 49 | + Version v; |
| 50 | + float f; |
| 51 | + |
| 52 | + bool success = PackageManifestUpdater.TryGetVersionComponents("x.2.3", out v, out f); |
| 53 | + Assert.IsFalse(success); |
| 54 | + Assert.IsNull(v); |
| 55 | + Assert.AreEqual(f, float.NaN); |
| 56 | + |
| 57 | + Debug.Log("Try to get version from improperly formatted prerelease."); |
| 58 | + |
| 59 | + v = new Version(5, 6, 7); |
| 60 | + f = 17f; |
| 61 | + success = PackageManifestUpdater.TryGetVersionComponents("1.2.3-v20200417.19", out v, out f); |
| 62 | + Assert.IsFalse(success); |
| 63 | + Assert.IsNull(v); |
| 64 | + Assert.AreEqual(f, float.NaN); |
| 65 | + |
| 66 | + Debug.Log("Try to get version from an empty string."); |
| 67 | + |
| 68 | + v = new Version(5, 6, 7); |
| 69 | + f = 17f; |
| 70 | + success = PackageManifestUpdater.TryGetVersionComponents("", out v, out f); |
| 71 | + Assert.IsFalse(success); |
| 72 | + Assert.IsNull(v); |
| 73 | + Assert.AreEqual(f, float.NaN); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Verifies that an outdated MSBuild for Unity version string will return the correct result. |
| 78 | + /// </summary> |
| 79 | + [Test] |
| 80 | + public void OutdatedMSBuild() |
| 81 | + { |
| 82 | + Debug.Log("Upgrade to new verion / prerelease"); |
| 83 | + string minVersion = "1.5.22-20200919.28"; |
| 84 | + string currentVersion = "0.7.15"; |
| 85 | + |
| 86 | + bool isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 87 | + Assert.IsFalse(isAppropriate); |
| 88 | + |
| 89 | + Debug.Log("Upgrade to new prerelease"); |
| 90 | + minVersion = "9.4.2-20200622.4"; |
| 91 | + currentVersion = "9.4.2-20200530.9"; |
| 92 | + isAppropriate = true; |
| 93 | + |
| 94 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 95 | + Assert.IsFalse(isAppropriate); |
| 96 | + |
| 97 | + Debug.Log("Upgrade to new version"); |
| 98 | + minVersion = "1.0.0"; |
| 99 | + currentVersion = "0.7.15"; |
| 100 | + isAppropriate = true; |
| 101 | + |
| 102 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 103 | + Assert.IsFalse(isAppropriate); |
| 104 | + |
| 105 | + Debug.Log("Upgrade prerelease to final"); |
| 106 | + minVersion = "0.9.19"; |
| 107 | + currentVersion = "0.9.19-20200101.55"; |
| 108 | + isAppropriate = true; |
| 109 | + |
| 110 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 111 | + Assert.IsFalse(isAppropriate); |
| 112 | + } |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Verifies that an exactly matching MSBuild for Unity version returns the correct result. |
| 116 | + /// </summary> |
| 117 | + [Test] |
| 118 | + public void MatchingMSBuild() |
| 119 | + { |
| 120 | + Debug.Log("Compare version"); |
| 121 | + string minVersion = "28.32.44"; |
| 122 | + string currentVersion = "28.32.44"; |
| 123 | + |
| 124 | + bool isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 125 | + Assert.IsTrue(isAppropriate); |
| 126 | + |
| 127 | + Debug.Log("Compare version / prerelease"); |
| 128 | + minVersion = "1.5.22-20200919.28"; |
| 129 | + currentVersion = "1.5.22-20200919.28"; |
| 130 | + isAppropriate = false; |
| 131 | + |
| 132 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 133 | + Assert.IsTrue(isAppropriate); |
| 134 | + } |
| 135 | + |
| 136 | + /// <summary> |
| 137 | + /// Verifies that a more recent MSBuild for Unity version returns the correct result. |
| 138 | + /// </summary> |
| 139 | + [Test] |
| 140 | + public void NewerMSBuild() |
| 141 | + { |
| 142 | + Debug.Log("Newer version"); |
| 143 | + string minVersion = "28.32.44"; |
| 144 | + string currentVersion = "28.32.45"; |
| 145 | + |
| 146 | + bool isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 147 | + Assert.IsTrue(isAppropriate); |
| 148 | + |
| 149 | + Debug.Log("Newer prerelease"); |
| 150 | + minVersion = "1.5.22-20200919.28"; |
| 151 | + currentVersion = "1.5.22-20200919.29"; |
| 152 | + isAppropriate = false; |
| 153 | + |
| 154 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 155 | + Assert.IsTrue(isAppropriate); |
| 156 | + |
| 157 | + Debug.Log("Newer version / prerelease"); |
| 158 | + minVersion = "1.5.22-20200919.28"; |
| 159 | + currentVersion = "1.6.30-20201031.6"; |
| 160 | + isAppropriate = false; |
| 161 | + |
| 162 | + isAppropriate = PackageManifestUpdater.IsAppropriateMBuildVersion(minVersion, currentVersion); |
| 163 | + Assert.IsTrue(isAppropriate); |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments