diff --git a/readme.md b/readme.md index e355c757..1d62ff03 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,7 @@ DiffEngine manages launching and cleanup of diff tools. It is designed to be use * [Closing a tool](#closing-a-tool) * [File type detection](#file-type-detection) * [BuildServerDetector](#buildserverdetector) + * [WSL](#wsl) * [Override in tests](#override-in-tests) * [Automatic AI detection](#automatic-ai-detection) * [Programmatic usage](#programmatic-usage) @@ -193,6 +194,33 @@ var isBitbucketPipelines = BuildServerDetector.IsBitbucketPipelines; +### WSL + +Running under [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) is not treated as a build server, since a WSL session is usually a developer machine. `BuildServerDetector.IsWsl` reports it, and `BuildServerDetector.Detected` ignores it. + +A build that runs its tests inside WSL from a Windows build agent is the case to watch. The variables the build server sets exist on the Windows side, and WSL only passes across the ones named in [WSLENV](https://learn.microsoft.com/en-us/windows/wsl/filesystems#share-environment-variables-between-windows-and-wsl-with-wslenv). So inside WSL nothing is detected, and diff tools are launched on the build agent. + +To have such a build detected, either name the build server's variable in `WSLENV` on the Windows side, for example on Azure DevOps: + +``` +set WSLENV=TF_BUILD:%WSLENV% +``` + +or set one of the detected variables on the command that starts the tests: + +``` +wsl -- env TF_BUILD=True dotnet test +``` + +To treat every WSL run as a build server, in a test: + +```cs +BuildServerDetector.Detected = BuildServerDetector.Detected || BuildServerDetector.IsWsl; +``` + +That value is scoped to the current async context, as described below. + + ### Override in tests `BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel. diff --git a/readme.source.md b/readme.source.md index 23206ecf..9ac3d547 100644 --- a/readme.source.md +++ b/readme.source.md @@ -89,6 +89,33 @@ There are also individual properties to check for each specific build system snippet: BuildServerDetectorProps +### WSL + +Running under [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) is not treated as a build server, since a WSL session is usually a developer machine. `BuildServerDetector.IsWsl` reports it, and `BuildServerDetector.Detected` ignores it. + +A build that runs its tests inside WSL from a Windows build agent is the case to watch. The variables the build server sets exist on the Windows side, and WSL only passes across the ones named in [WSLENV](https://learn.microsoft.com/en-us/windows/wsl/filesystems#share-environment-variables-between-windows-and-wsl-with-wslenv). So inside WSL nothing is detected, and diff tools are launched on the build agent. + +To have such a build detected, either name the build server's variable in `WSLENV` on the Windows side, for example on Azure DevOps: + +``` +set WSLENV=TF_BUILD:%WSLENV% +``` + +or set one of the detected variables on the command that starts the tests: + +``` +wsl -- env TF_BUILD=True dotnet test +``` + +To treat every WSL run as a build server, in a test: + +```cs +BuildServerDetector.Detected = BuildServerDetector.Detected || BuildServerDetector.IsWsl; +``` + +That value is scoped to the current async context, as described below. + + ### Override in tests `BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel. diff --git a/src/DiffEngine/BuildServerDetector.cs b/src/DiffEngine/BuildServerDetector.cs index d0e92fd2..485c70da 100644 --- a/src/DiffEngine/BuildServerDetector.cs +++ b/src/DiffEngine/BuildServerDetector.cs @@ -65,7 +65,6 @@ static BuildServerDetector() IsMyGet || IsGoDc || IsDocker || - IsWsl || IsAppVeyor || IsBitbucketPipelines; } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0d39a80b..69ab8b7d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - 20.7.2 + 20.8.0 1.0.0 Testing, Snapshot, Diff, Compare Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.