Skip to content

Commit 2e68b6e

Browse files
mdh1418Mitchell Hwang
and
Mitchell Hwang
authored
[wasm] Skip Assert.InRange in Copy.cs for Browser (#41000)
* Revert "[Wasm] Enable CopyWithData FileSystem test (#40663)" This reverts commit 1821567. * Provide context for skipping Assert in Copy.cs Co-authored-by: Mitchell Hwang <[email protected]>
1 parent 982e275 commit 2e68b6e

File tree

1 file changed

+12
-34
lines changed
  • src/libraries/System.IO.FileSystem/tests/File

1 file changed

+12
-34
lines changed

src/libraries/System.IO.FileSystem/tests/File/Copy.cs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ protected virtual void Copy(string source, string dest)
1414
File.Copy(source, dest);
1515
}
1616

17-
protected virtual void CopyReadOnlyFile(string source, string dest)
18-
{
19-
byte[] bits = File.ReadAllBytes(source);
20-
File.WriteAllBytes(dest, bits);
21-
File.SetAttributes(dest, FileAttributes.ReadOnly);
22-
}
23-
2417
#region UniversalTests
2518

2619
[Fact]
@@ -115,7 +108,6 @@ public static IEnumerable<object[]> CopyFileWithData_MemberData()
115108

116109
[Theory]
117110
[MemberData(nameof(CopyFileWithData_MemberData))]
118-
[ActiveIssue("https://github.com/dotnet/runtime/issues/40867", TestPlatforms.Browser)]
119111
public void CopyFileWithData(char[] data, bool readOnly)
120112
{
121113
string testFileSource = GetTestFilePath();
@@ -127,21 +119,8 @@ public void CopyFileWithData(char[] data, bool readOnly)
127119
stream.Write(data, 0, data.Length);
128120
}
129121

130-
DateTime lastWriteTime;
131-
if (PlatformDetection.IsBrowser)
132-
{
133-
// For browser, there is technically only 1 time. It's the max
134-
// of LastWrite and LastAccess. Setting to a date/time in the future
135-
// is a way of making this test work similarly.
136-
//
137-
// https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.utime
138-
//
139-
lastWriteTime = DateTime.UtcNow.Add(TimeSpan.FromHours(1));
140-
}
141-
else
142-
{
143-
lastWriteTime = DateTime.UtcNow.Subtract(TimeSpan.FromHours(1));
144-
}
122+
// Set the last write time of the source file to something a while ago
123+
DateTime lastWriteTime = DateTime.UtcNow.Subtract(TimeSpan.FromHours(1));
145124
File.SetLastWriteTime(testFileSource, lastWriteTime);
146125

147126
if (readOnly)
@@ -150,16 +129,7 @@ public void CopyFileWithData(char[] data, bool readOnly)
150129
}
151130

152131
// Copy over the data
153-
//
154-
// For browser, work around limitation of File.Copy, which
155-
// fails when trying to open the dest file
156-
if (PlatformDetection.IsBrowser && readOnly)
157-
{
158-
CopyReadOnlyFile(testFileSource, testFileDest);
159-
File.SetLastWriteTime(testFileDest, lastWriteTime);
160-
}
161-
else
162-
Copy(testFileSource, testFileDest);
132+
Copy(testFileSource, testFileDest);
163133

164134
// Ensure copy transferred written data
165135
using (StreamReader stream = new StreamReader(File.OpenRead(testFileDest)))
@@ -170,7 +140,15 @@ public void CopyFileWithData(char[] data, bool readOnly)
170140
}
171141

172142
// Ensure last write/access time on the new file is appropriate
173-
Assert.InRange(File.GetLastWriteTimeUtc(testFileDest), lastWriteTime.AddSeconds(-1), lastWriteTime.AddSeconds(1));
143+
//
144+
// For browser, there is technically only 1 time. It's the max
145+
// of LastWrite and LastAccess. On browser, File.SetLastWriteTime
146+
// overwrites LastWrite and LastAccess, and File.Copy
147+
// overwrites LastWrite , so this check doesn't apply.
148+
if (PlatformDetection.IsNotBrowser)
149+
{
150+
Assert.InRange(File.GetLastWriteTimeUtc(testFileDest), lastWriteTime.AddSeconds(-1), lastWriteTime.AddSeconds(1));
151+
}
174152

175153
Assert.Equal(readOnly, (File.GetAttributes(testFileDest) & FileAttributes.ReadOnly) != 0);
176154
if (readOnly)

0 commit comments

Comments
 (0)