Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -193,6 +194,33 @@ var isBitbucketPipelines = BuildServerDetector.IsBitbucketPipelines;
<!-- endSnippet -->


### 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.
Expand Down
27 changes: 27 additions & 0 deletions readme.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/DiffEngine/BuildServerDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static BuildServerDetector()
IsMyGet ||
IsGoDc ||
IsDocker ||
IsWsl ||
IsAppVeyor ||
IsBitbucketPipelines;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>20.7.2</Version>
<Version>20.8.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Testing, Snapshot, Diff, Compare</PackageTags>
<Description>Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.</Description>
Expand Down
Loading