diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 978e0f0..d475752 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,7 @@ Use the following shell command: ```console $ dotnet test ``` +Tests involving symlink creation require elevated privileges on Windows, as this is enforced at the OS level. Test Documentation ------------------ diff --git a/TruePath.Tests/AbsolutePathTests.cs b/TruePath.Tests/AbsolutePathTests.cs index e9fa601..c7f784e 100644 --- a/TruePath.Tests/AbsolutePathTests.cs +++ b/TruePath.Tests/AbsolutePathTests.cs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 Friedrich von Never +// SPDX-FileCopyrightText: 2024-2026 TruePath contributors // // SPDX-License-Identifier: MIT @@ -91,7 +91,18 @@ public void ReadKind_IsSymlink() var tempDirectoryInfo = Path.GetTempPath(); - Directory.CreateSymbolicLink(currentDirectory, tempDirectoryInfo); + try + { + Directory.CreateSymbolicLink(currentDirectory, tempDirectoryInfo); + } + catch (IOException e) when (OperatingSystem.IsWindows() && !Utils.RunsOnCi()) + { + if (e.Message.Contains("privilege") && (e.StackTrace?.Contains("CreateSymbolicLink") ?? false)) + { + Assert.Skip("Tests involving symlink creation require elevated privileges on Windows, as this is enforced at the OS level."); + } + else throw; + } // Act var kind = localPath.ReadKind(); diff --git a/TruePath.Tests/LocalPathTests.cs b/TruePath.Tests/LocalPathTests.cs index 716f01a..baeeb3d 100644 --- a/TruePath.Tests/LocalPathTests.cs +++ b/TruePath.Tests/LocalPathTests.cs @@ -1,9 +1,7 @@ -// SPDX-FileCopyrightText: 2024 Friedrich von Never +// SPDX-FileCopyrightText: 2024-2026 TruePath contributors // // SPDX-License-Identifier: MIT -using Xunit.Abstractions; - namespace TruePath.Tests; public class LocalPathTests(ITestOutputHelper output) diff --git a/TruePath.Tests/NormalizationTests.cs b/TruePath.Tests/NormalizationTests.cs index 8b6a2d2..227f869 100644 --- a/TruePath.Tests/NormalizationTests.cs +++ b/TruePath.Tests/NormalizationTests.cs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024-2025 TruePath contributors +// SPDX-FileCopyrightText: 2024-2026 TruePath contributors // // SPDX-License-Identifier: MIT @@ -6,7 +6,6 @@ using FsCheck.Fluent; using FsCheck.Xunit; using JetBrains.Annotations; -using Xunit.Abstractions; namespace TruePath.Tests; diff --git a/TruePath.Tests/TruePath.Tests.csproj b/TruePath.Tests/TruePath.Tests.csproj index a550166..fca8ab8 100644 --- a/TruePath.Tests/TruePath.Tests.csproj +++ b/TruePath.Tests/TruePath.Tests.csproj @@ -1,5 +1,5 @@ @@ -14,14 +14,14 @@ SPDX-License-Identifier: MIT - + - runtime; build; native; contentfiles; analyzers; buildtransitive all + diff --git a/TruePath.Tests/Utils.cs b/TruePath.Tests/Utils.cs index 86b49de..ccc8111 100644 --- a/TruePath.Tests/Utils.cs +++ b/TruePath.Tests/Utils.cs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 TruePath contributors +// SPDX-FileCopyrightText: 2024-2026 TruePath contributors // // SPDX-License-Identifier: MIT @@ -22,4 +22,9 @@ internal static string ToNonCanonicalCase(this string path) return nonCanonicalPath; } + + internal static bool RunsOnCi() + { + return Environment.GetEnvironmentVariable("CI") is not null; + } }