|
| 1 | +using System.Runtime.InteropServices; |
1 | 2 | using Xunit; |
2 | 3 | using Xunit.Abstractions; |
3 | 4 |
|
@@ -144,6 +145,28 @@ public void GenerateAssetBundleName_LogicTest() { |
144 | 145 | } |
145 | 146 | } |
146 | 147 |
|
| 148 | + [Fact] |
| 149 | + public void GenerateAssetBundleName_NoTargetLogicTest() { |
| 150 | + // Test the naming logic for no platform suffix without requiring Unity |
| 151 | + var testCases = new[] |
| 152 | + { |
| 153 | + new { BundleName = "author.modname", Expected = "resource_author_modname" }, |
| 154 | + new { BundleName = "mymod", Expected = "resource_mymod" }, |
| 155 | + new { BundleName = "test.bundle", Expected = "resource_test_bundle" }, |
| 156 | + new { BundleName = "complex.name.with.dots", Expected = "resource_complex_name_with_dots" }, |
| 157 | + new { BundleName = "simple", Expected = "resource_simple" } |
| 158 | + }; |
| 159 | + |
| 160 | + foreach (var testCase in testCases) { |
| 161 | + // Simulate the naming logic from ModAssetBundleBuilder.cs when noPlatformSuffix = true |
| 162 | + var normalizedBundleName = testCase.BundleName.Replace(".", "_"); |
| 163 | + var actualResult = $"resource_{normalizedBundleName}"; // No platform suffix |
| 164 | + |
| 165 | + _output.WriteLine($"Input: '{testCase.BundleName}' (no target) -> '{actualResult}'"); |
| 166 | + Assert.Equal(testCase.Expected, actualResult); |
| 167 | + } |
| 168 | + } |
| 169 | + |
147 | 170 | [Theory] |
148 | 171 | [InlineData("windows")] |
149 | 172 | [InlineData("linux")] |
@@ -200,6 +223,86 @@ public async Task CreateAssetBundle_DifferentTargets_ShouldIncludeTargetInName(s |
200 | 223 | if (File.Exists(manifestFile)) File.Delete(manifestFile); |
201 | 224 | } |
202 | 225 |
|
| 226 | + [Fact] |
| 227 | + public async Task CreateAssetBundle_NoTargetSpecified_ShouldNotIncludePlatformSuffix() { |
| 228 | + // Skip test in CI environments or if Unity is not available |
| 229 | + var isCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) || |
| 230 | + !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS")); |
| 231 | + |
| 232 | + if (isCI) { |
| 233 | + _output.WriteLine("Skipping test: Unity tests are disabled in CI environment"); |
| 234 | + return; |
| 235 | + } |
| 236 | + |
| 237 | + var unityPath = UnityPathFinder.FindUnityExecutable("2022.3.35f1"); |
| 238 | + if (string.IsNullOrEmpty(unityPath)) { |
| 239 | + _output.WriteLine("Skipping test: Unity 2022.3.35f1 not found"); |
| 240 | + return; |
| 241 | + } |
| 242 | + |
| 243 | + // Verify test assets exist |
| 244 | + if (!Directory.Exists(_testAssetsPath)) { |
| 245 | + _output.WriteLine($"Skipping test: TestAssets directory not found at {_testAssetsPath}"); |
| 246 | + return; |
| 247 | + } |
| 248 | + |
| 249 | + const string bundleName = "no.target.test"; |
| 250 | + var expectedFileName = "resource_no_target_test"; // No platform suffix expected |
| 251 | + |
| 252 | + var config = new BuildConfiguration |
| 253 | + { |
| 254 | + UnityPath = unityPath, |
| 255 | + UnityVersion = "2022.3.35f1", |
| 256 | + AssetDirectory = _testAssetsPath, |
| 257 | + OutputDirectory = _testOutputPath, |
| 258 | + BundleName = bundleName, |
| 259 | + BuildTarget = "", // Empty string means auto-detect current OS without platform suffix |
| 260 | + KeepTempProject = false, |
| 261 | + CleanTempProject = true, |
| 262 | + LinkMethod = "copy" |
| 263 | + }; |
| 264 | + |
| 265 | + _output.WriteLine($"Testing default behavior: '{bundleName}' -> '{expectedFileName}' (no platform suffix)"); |
| 266 | + |
| 267 | + var success = await BuildAssetBundleAsync(config); |
| 268 | + Assert.True(success, "Asset bundle creation failed for default (no target) case"); |
| 269 | + |
| 270 | + // Verify the platform suffix is NOT included in the filename |
| 271 | + var expectedBundleFile = Path.Combine(_testOutputPath, expectedFileName); |
| 272 | + var expectedManifestFile = Path.Combine(_testOutputPath, expectedFileName + ".manifest"); |
| 273 | + |
| 274 | + _output.WriteLine($"Looking for bundle file at: {expectedBundleFile}"); |
| 275 | + _output.WriteLine($"Looking for manifest file at: {expectedManifestFile}"); |
| 276 | + |
| 277 | + // List all files in output directory for debugging |
| 278 | + var outputFiles = Directory.GetFiles(_testOutputPath, "*", SearchOption.AllDirectories); |
| 279 | + _output.WriteLine("Files in output directory:"); |
| 280 | + foreach (var file in outputFiles) |
| 281 | + _output.WriteLine($" {Path.GetRelativePath(_testOutputPath, file)} ({new FileInfo(file).Length} bytes)"); |
| 282 | + |
| 283 | + Assert.True(File.Exists(expectedBundleFile), |
| 284 | + $"Bundle file should NOT include platform suffix when no target specified: {expectedFileName}"); |
| 285 | + Assert.True(File.Exists(expectedManifestFile), |
| 286 | + $"Manifest file should NOT include platform suffix when no target specified: {expectedFileName}.manifest"); |
| 287 | + |
| 288 | + // Verify no platform-suffixed files exist (verify that we don't accidentally get the old behavior) |
| 289 | + var currentOS = DetectCurrentOSForTest(); |
| 290 | + var withSuffixFile = Path.Combine(_testOutputPath, $"resource_no_target_test_{currentOS}"); |
| 291 | + Assert.False(File.Exists(withSuffixFile), |
| 292 | + $"Bundle file with platform suffix should NOT exist when no target specified: {withSuffixFile}"); |
| 293 | + |
| 294 | + // Clean up |
| 295 | + if (File.Exists(expectedBundleFile)) File.Delete(expectedBundleFile); |
| 296 | + if (File.Exists(expectedManifestFile)) File.Delete(expectedManifestFile); |
| 297 | + } |
| 298 | + |
| 299 | + private static string DetectCurrentOSForTest() { |
| 300 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return "windows"; |
| 301 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return "mac"; |
| 302 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return "linux"; |
| 303 | + return "unknown"; |
| 304 | + } |
| 305 | + |
203 | 306 | private Task<bool> BuildAssetBundleAsync(BuildConfiguration config) { |
204 | 307 | return Task.Run(() => |
205 | 308 | { |
|
0 commit comments