Skip to content

Commit

Permalink
Merge branch 'main' into topic/fix-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Dec 16, 2024
2 parents 3debb50 + e855d61 commit c3ab27f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ protected override bool IsDirectorySeparator(char c)
protected override bool IsEffectivelyEmpty(string path)
=> string.IsNullOrEmpty(path);

#if FEATURE_PATH_RELATIVE
/// <summary>
/// https://github.com/dotnet/runtime/blob/v8.0.4/src/libraries/Common/src/System/IO/PathInternal.Unix.cs#L77
/// </summary>
protected override bool IsPartiallyQualified(string path)
=> !IsPathRooted(path);
#endif

/// <summary>
/// https://github.com/dotnet/runtime/blob/v8.0.4/src/libraries/Common/src/System/IO/PathInternal.Unix.cs#L39
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ string NormalizePath(string path)
return sb.ToString();
}

#if FEATURE_PATH_RELATIVE
/// <summary>
/// We have the same root, we need to calculate the difference now using the
/// common Length and Segment count past the length.
Expand Down Expand Up @@ -606,7 +607,9 @@ private string CreateRelativePath(string relativeTo, string path, int commonLeng

return sb.ToString();
}
#endif

#if FEATURE_PATH_RELATIVE
/// <summary>
/// Get the common path length from the start of the string.
/// </summary>
Expand Down Expand Up @@ -653,12 +656,15 @@ private int GetCommonPathLength(string first, string second,

return commonChars;
}
#endif

protected abstract int GetRootLength(string path);
protected abstract bool IsDirectorySeparator(char c);
protected abstract bool IsEffectivelyEmpty(string path);

#if FEATURE_PATH_RELATIVE
protected abstract bool IsPartiallyQualified(string path);
#endif

#if FEATURE_PATH_JOIN || FEATURE_PATH_ADVANCED
private string JoinInternal(string?[] paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ protected override bool IsEffectivelyEmpty(string path)
return path.All(c => c == ' ');
}

#if FEATURE_PATH_RELATIVE
/// <summary>
/// https://github.com/dotnet/runtime/blob/v8.0.4/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L250
/// </summary>
Expand Down Expand Up @@ -279,6 +280,7 @@ protected override bool IsPartiallyQualified(string path)
// not qualified if you don't have a valid drive. "=:\" is the "=" file's default data stream.
&& IsValidDriveChar(path[0]));
}
#endif

/// <summary>
/// Returns true if the given character is a valid drive letter
Expand Down
22 changes: 11 additions & 11 deletions Tests/Testably.Abstractions.Testing.Tests/NotificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public void AwaitableCallback_Amount_ShouldOnlyReturnAfterNumberOfCallbacks()
}
});

_ = Task.Run(() =>
_ = Task.Run(async () =>
{
Thread.Sleep(10);
await Task.Delay(10);
for (int i = 1; i <= 10; i++)
{
timeSystem.Thread.Sleep(i);
Thread.Sleep(1);
await Task.Delay(1);
}
});

Expand Down Expand Up @@ -82,13 +82,13 @@ public void AwaitableCallback_Filter_ShouldOnlyUpdateAfterFilteredValue()
receivedCount++;
});

_ = Task.Run(() =>
_ = Task.Run(async () =>
{
Thread.Sleep(10);
await Task.Delay(10);
for (int i = 1; i <= 10; i++)
{
timeSystem.Thread.Sleep(i);
Thread.Sleep(1);
await Task.Delay(1);
}
});

Expand All @@ -107,16 +107,16 @@ public void AwaitableCallback_Predicate_ShouldOnlyUpdateAfterFilteredValue()
receivedCount++;
}, t => t.TotalMilliseconds > 6);

_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
Thread.Sleep(10);
await Task.Delay(10);
for (int i = 1; i <= 10; i++)
{
timeSystem.Thread.Sleep(i);
Thread.Sleep(1);
await Task.Delay(1);
}

ms.Set();
Expand Down Expand Up @@ -145,15 +145,15 @@ public void AwaitableCallback_ShouldWaitForCallbackExecution()
isCalled = true;
});

_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
while (!ms.IsSet)
{
timeSystem.Thread.Sleep(1);
Thread.Sleep(1);
await Task.Delay(1);
}
}
catch (ObjectDisposedException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Testably.Abstractions.Testing.Statistics;
using Testably.Abstractions.Testing.Tests.TestHelpers;
// ReSharper disable MethodSupportsCancellation

namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem;

Expand Down Expand Up @@ -46,11 +47,11 @@ public void Method_WaitForChanged_WatcherChangeTypes_Int_ShouldRegisterCall()
// Changes in the background are necessary, so that FileSystemWatcher.WaitForChanged returns.
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(30));
CancellationToken token = cts.Token;
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
while (!token.IsCancellationRequested)
{
Thread.Sleep(10);
await Task.Delay(10);
sut.Directory.CreateDirectory(sut.Path.Combine("foo", "some-directory"));
sut.Directory.Delete(sut.Path.Combine("foo", "some-directory"));
}
Expand All @@ -76,11 +77,11 @@ public void Method_WaitForChanged_WatcherChangeTypes_ShouldRegisterCall()
// Changes in the background are necessary, so that FileSystemWatcher.WaitForChanged returns.
using CancellationTokenSource cts = new();
CancellationToken token = cts.Token;
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
while (!token.IsCancellationRequested)
{
Thread.Sleep(10);
await Task.Delay(10);
sut.Directory.CreateDirectory(sut.Path.Combine("foo", "some-directory"));
sut.Directory.Delete(sut.Path.Combine("foo", "some-directory"));
}
Expand All @@ -105,11 +106,11 @@ public void Method_WaitForChanged_WatcherChangeTypes_TimeSpan_ShouldRegisterCall
// Changes in the background are necessary, so that FileSystemWatcher.WaitForChanged returns.
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(30));
CancellationToken token = cts.Token;
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
while (!token.IsCancellationRequested)
{
Thread.Sleep(10);
await Task.Delay(10);
sut.Directory.CreateDirectory(sut.Path.Combine("foo", "some-directory"));
sut.Directory.Delete(sut.Path.Combine("foo", "some-directory"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
// ReSharper disable MethodSupportsCancellation
// ReSharper disable MethodHasAsyncOverloadWithCancellation

namespace Testably.Abstractions.Tests.FileSystem.FileSystemWatcher;

Expand Down Expand Up @@ -41,7 +43,7 @@ void FileSystemWatcherOnChanged(object sender, FileSystemEventArgs e)

try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
Expand All @@ -51,7 +53,7 @@ void FileSystemWatcherOnChanged(object sender, FileSystemEventArgs e)
{
string content = i++.ToString(CultureInfo.InvariantCulture);
FileSystem.File.WriteAllText(path, content);
Thread.Sleep(10);
await Task.Delay(10);
ms1.Set();
}
}
Expand Down Expand Up @@ -114,7 +116,7 @@ void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs e)

try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
Expand All @@ -123,7 +125,7 @@ void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs e)
{
FileSystem.Directory.CreateDirectory(path);
FileSystem.Directory.Delete(path);
Thread.Sleep(10);
await Task.Delay(10);
ms1.Set();
}
}
Expand Down Expand Up @@ -184,7 +186,7 @@ void FileSystemWatcherOnDeleted(object sender, FileSystemEventArgs e)

try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
Expand All @@ -193,7 +195,7 @@ void FileSystemWatcherOnDeleted(object sender, FileSystemEventArgs e)
{
FileSystem.Directory.CreateDirectory(path);
FileSystem.Directory.Delete(path);
Thread.Sleep(10);
await Task.Delay(10);
ms1.Set();
}
}
Expand Down Expand Up @@ -255,7 +257,7 @@ void FileSystemWatcherOnRenamed(object sender, FileSystemEventArgs e)

try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
Expand All @@ -265,7 +267,7 @@ void FileSystemWatcherOnRenamed(object sender, FileSystemEventArgs e)
while (!token.IsCancellationRequested)
{
FileSystem.File.Move($"path-{i}", $"path-{++i}");
Thread.Sleep(10);
await Task.Delay(10);
ms1.Set();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public void BeginInit_ShouldStopListening(string path)
fileSystemWatcher.EnableRaisingEvents.Should().BeTrue();
try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
while (!ms.IsSet)
{
Thread.Sleep(10);
await Task.Delay(10);
FileSystem.Directory.CreateDirectory(path);
FileSystem.Directory.Delete(path);
}
Expand Down Expand Up @@ -86,14 +86,14 @@ public void EndInit_ShouldRestartListening(string path)
fileSystemWatcher.EnableRaisingEvents.Should().BeTrue();
try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
while (!ms.IsSet)
{
Thread.Sleep(10);
await Task.Delay(10);
FileSystem.Directory.CreateDirectory(path);
FileSystem.Directory.Delete(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public void WaitForChanged_ShouldBlockUntilEventHappens(string path)
FileSystem.FileSystemWatcher.New(BasePath);
try
{
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
while (!ms.IsSet)
{
Thread.Sleep(10);
await Task.Delay(10);
FileSystem.Directory.CreateDirectory(path);
FileSystem.Directory.Delete(path);
}
Expand Down Expand Up @@ -68,14 +68,14 @@ public void WaitForChanged_Timeout_ShouldReturnTimedOut(string path,
try
{
fileSystemWatcher.EnableRaisingEvents = true;
_ = Task.Run(() =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
while (!ms.IsSet)
{
Thread.Sleep(10);
await Task.Delay(10);
FileSystem.Directory.CreateDirectory(fullPath);
FileSystem.Directory.Delete(fullPath);
}
Expand Down

0 comments on commit c3ab27f

Please sign in to comment.