Skip to content

Commit 7336d5e

Browse files
Address Copilot review feedback
- Fix typo (its -> it's) in DumpArchive comment - Document that filtered dumps omit External References (command-dump.md, textdumper.md) - Add tests: type-filter omits External References, --stdout/-o mutual exclusion error, multi-SerializedFile archive refusal (data.unity3d) - Assert no .txt file is written by --stdout in DumpText_Stdout_WritesDumpToStdout
1 parent b7a9f48 commit 7336d5e

5 files changed

Lines changed: 74 additions & 3 deletions

File tree

Documentation/command-dump.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ UnityDataTool dump /path/to/file.bundle --typetree-data /path/to/typetree.bin
145145

146146
## Output Format
147147

148-
The output is similar to Unity's `binary2text` tool. Each file begins with external references:
148+
The output is similar to Unity's `binary2text` tool. Unfiltered dumps begin with external references (when filtering with `-i` or `-t` this section is omitted — use the [`serialized-file externalrefs`](#) command if you want them separately):
149149

150150
```
151151
External References

Documentation/textdumper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ There will be one output file per SerializedFile. Depending on the type of the i
1515
be more than one output file (e.g. AssetBundles are archives that can contain several
1616
SerializedFiles).
1717

18-
The first lines of the output file looks like this:
18+
For an unfiltered dump, the first lines of the output file look like this (when `ObjectId` or `TypeFilter` are set the External References section is omitted, and the output starts directly with the matching object entries):
1919

2020
External References
2121
path(1): "Library/unity default resources" GUID: 0000000000000000e000000000000000 Type: 0

TextDumper/TextDumperTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int DumpSerializedFile(DumpOptions options)
9999
}
100100

101101
// For convenience we also support directly dumping serialized files that are inside an archive,
102-
// so that its not necessary to use `archive extract` if you only want to see values from the object serialization.
102+
// so that it's not necessary to use `archive extract` if you only want to see values from the object serialization.
103103
int DumpArchive(DumpOptions options)
104104
{
105105
using var archive = UnityFileSystem.MountArchive(options.Path, "/");

UnityDataTool.Tests/DumpTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public class DumpTests
1212
private string m_TestDataFolder;
1313
private string m_SerializedFilePath;
1414
private string m_ResourceFilePath;
15+
private string m_MultiSerializedFileArchivePath;
1516

1617
[OneTimeSetUp]
1718
public void OneTimeSetup()
1819
{
1920
m_TestDataFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data");
2021
m_SerializedFilePath = Path.Combine(m_TestDataFolder, "PlayerWithTypeTrees", "level0");
2122
m_ResourceFilePath = Path.Combine(m_TestDataFolder, "PlayerWithTypeTrees", "sharedassets0.assets.resS");
23+
m_MultiSerializedFileArchivePath = Path.Combine(m_TestDataFolder, "PlayerDataCompressed", "data.unity3d");
2224
}
2325

2426
[Test]
@@ -99,6 +101,72 @@ public async Task Dump_Stdout_FilterByObjectId_DoesNotIncludeExternalReferences(
99101
Assert.That(output, Does.Not.Contain("External References"));
100102
}
101103

104+
[Test]
105+
public async Task Dump_Stdout_FilterByType_DoesNotIncludeExternalReferences()
106+
{
107+
using var sw = new StringWriter();
108+
var currentOut = Console.Out;
109+
try
110+
{
111+
Console.SetOut(sw);
112+
Assert.AreEqual(0, await Program.Main(new string[] { "dump", m_SerializedFilePath, "--stdout", "-t", "RenderSettings" }));
113+
}
114+
finally
115+
{
116+
Console.SetOut(currentOut);
117+
}
118+
119+
var output = sw.ToString();
120+
Assert.That(output, Does.Contain("(ClassID: 104)"));
121+
Assert.That(output, Does.Not.Contain("External References"));
122+
}
123+
124+
[Test]
125+
public async Task Dump_Stdout_WithOutputPath_ReturnsError()
126+
{
127+
using var swOut = new StringWriter();
128+
using var swErr = new StringWriter();
129+
var currentOut = Console.Out;
130+
var currentErr = Console.Error;
131+
try
132+
{
133+
Console.SetOut(swOut);
134+
Console.SetError(swErr);
135+
Assert.AreNotEqual(0, await Program.Main(new string[] { "dump", m_SerializedFilePath, "--stdout", "-o", m_TestDataFolder }));
136+
}
137+
finally
138+
{
139+
Console.SetOut(currentOut);
140+
Console.SetError(currentErr);
141+
}
142+
143+
Assert.That(swErr.ToString(), Does.Contain("--stdout and -o/--output-path are mutually exclusive."));
144+
}
145+
146+
[Test]
147+
public async Task Dump_Stdout_MultipleSerializedFilesArchive_Refused()
148+
{
149+
using var swOut = new StringWriter();
150+
using var swErr = new StringWriter();
151+
var currentOut = Console.Out;
152+
var currentErr = Console.Error;
153+
try
154+
{
155+
Console.SetOut(swOut);
156+
Console.SetError(swErr);
157+
Assert.AreNotEqual(0, await Program.Main(new string[] { "dump", m_MultiSerializedFileArchivePath, "--stdout", "-t", "MonoBehaviour" }));
158+
}
159+
finally
160+
{
161+
Console.SetOut(currentOut);
162+
Console.SetError(currentErr);
163+
}
164+
165+
var err = swErr.ToString();
166+
Assert.That(err, Does.Contain("--stdout cannot be used with an archive containing multiple SerializedFiles"));
167+
Assert.That(err, Does.Contain("(5 found)"));
168+
}
169+
102170
[Test]
103171
public async Task Dump_Stdout_FilterByObjectId_NotFound_PrintsNotFoundMessage()
104172
{

UnityDataTool.Tests/UnityDataToolAssetBundleTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public async Task DumpText_SkipLargeArrays_TextFileCreatedCorrectly(
152152
public async Task DumpText_Stdout_WritesDumpToStdout()
153153
{
154154
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
155+
var unwantedOutputFile = Path.Combine(m_TestOutputFolder, "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt");
155156

156157
using var sw = new StringWriter();
157158
var currentOut = Console.Out;
@@ -165,6 +166,8 @@ public async Task DumpText_Stdout_WritesDumpToStdout()
165166
Console.SetOut(currentOut);
166167
}
167168

169+
Assert.IsFalse(File.Exists(unwantedOutputFile), "--stdout should not also write a .txt file");
170+
168171
var content = sw.ToString();
169172
var expected = File.ReadAllText(Path.Combine(Context.ExpectedDataFolder, "dump", "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt"));
170173

0 commit comments

Comments
 (0)