Skip to content

Use nullable #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 0 additions & 7 deletions SampleTestAssembly/SampleTestAssembly.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -66,12 +65,6 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
1 change: 0 additions & 1 deletion SampleTestAssembly/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net452" developmentDependency="true" />
<package id="xunit" version="2.1.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
Expand Down
2 changes: 1 addition & 1 deletion xunit.runner.data/ClientReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class ClientReader : IDisposable
{
private readonly BinaryReader _reader;
private bool _closed;
private Exception _exception;
private Exception? _exception;

public bool IsConnected => !_closed;

Expand Down
5 changes: 0 additions & 5 deletions xunit.runner.data/xunit.runner.data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
<Compile Include="TestDataKind.cs" />
<Compile Include="TestResultData.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers">
<Version>2.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 0 additions & 1 deletion xunit.runner.worker/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net46" developmentDependency="true" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.runner.utility" version="2.1.0" targetFramework="net46" />
</packages>
7 changes: 0 additions & 7 deletions xunit.runner.worker/xunit.runner.worker.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -77,12 +76,6 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
8 changes: 3 additions & 5 deletions xunit.runner.wpf/CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ public static void SetRegistration(UIElement element, CommandBindingCollection v
}
}

public static CommandBindingCollection GetRegistration(UIElement element)
public static CommandBindingCollection? GetRegistration(UIElement element)
=> (element != null ? (CommandBindingCollection)element.GetValue(Registration) : null);

private static void OnRegistrationChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
UIElement element = sender as UIElement;
if (element != null)
if (sender is UIElement element)
{
CommandBindingCollection bindings = e.NewValue as CommandBindingCollection;
if (bindings != null)
if (e.NewValue is CommandBindingCollection bindings)
{
element.CommandBindings.AddRange(bindings);
}
Expand Down
2 changes: 1 addition & 1 deletion xunit.runner.wpf/Converters/TestStateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static BitmapImage LoadResourceImage(string resourceName)
return image;
}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var state = (TestState)value;
if (targetType == typeof(Brush))
Expand Down
8 changes: 7 additions & 1 deletion xunit.runner.wpf/FilteredCollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,13 @@ void IList.RemoveAt(int index)

object IList.this[int index]
{
get { return this[index]; }
get
{
// Can't figure out how to not get a warning here.
#pragma warning disable CS8603
return this[index];
#pragma warning restore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a ?? throw here to remove the exception. That will function. Don't think that can be a shipping solution though.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, and the warning didn't go away - maybe a bug in the preview.

}
set { throw new NotSupportedException(); }
}

Expand Down
11 changes: 5 additions & 6 deletions xunit.runner.wpf/Impl/RemoteTestUtil.BackgroundRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ private void GoOnBackground()
/// <typeparam name="T"></typeparam>
private sealed class BackgroundReader<T> where T : class
{
private readonly ConcurrentQueue<T> _queue;
private readonly ConcurrentQueue<T?> _queue;
private readonly ClientReader _reader;
private readonly Func<ClientReader, T> _readValue;

internal ClientReader Reader => _reader;

internal BackgroundReader(ConcurrentQueue<T> queue, ClientReader reader, Func<ClientReader, T> readValue)
internal BackgroundReader(ConcurrentQueue<T?> queue, ClientReader reader, Func<ClientReader, T> readValue)
{
_queue = queue;
_reader = reader;
Expand Down Expand Up @@ -111,7 +111,7 @@ private sealed class BackgroundProducer<T> where T : class
private const int MaxResultPerTick = 1000;

private readonly Connection _connection;
private readonly ConcurrentQueue<T> _queue;
private readonly ConcurrentQueue<T?> _queue;
private readonly DispatcherTimer _timer;
private readonly Action<List<T>> _callback;
private readonly int _maxPerTick;
Expand All @@ -122,7 +122,7 @@ private sealed class BackgroundProducer<T> where T : class
internal BackgroundProducer(
Connection connection,
Dispatcher dispatcher,
ConcurrentQueue<T> queue,
ConcurrentQueue<T?> queue,
Action<List<T>> callback,
int maxResultPerTick = MaxResultPerTick,
TimeSpan? interval = null)
Expand All @@ -144,8 +144,7 @@ private void OnTimerTick(object sender, EventArgs e)
var i = 0;
var list = new List<T>();
var isDone = false;
T value;
while (i < _maxPerTick && _queue.TryDequeue(out value))
while (i < _maxPerTick && _queue.TryDequeue(out T? value))
{
if (value == null)
{
Expand Down
4 changes: 2 additions & 2 deletions xunit.runner.wpf/Impl/RemoteTestUtil.Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed partial class RemoteTestUtil : ITestUtil
{
private sealed class Connection : IDisposable
{
private NamedPipeClientStream _stream;
private NamedPipeClientStream? _stream;
private ClientReader _reader;

internal NamedPipeClientStream Stream => _stream;
internal NamedPipeClientStream Stream => _stream ?? throw new ObjectDisposedException(nameof(Connection));

internal ClientReader Reader => _reader;

Expand Down
2 changes: 1 addition & 1 deletion xunit.runner.wpf/Impl/RemoteTestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private async Task RunCore(string actionName, string assemblyPath, ImmutableArra
private async Task ProcessResultsCore<T>(Connection connection, Func<ClientReader, T> readValue, Action<List<T>> callback, CancellationToken cancellationToken)
where T : class
{
var queue = new ConcurrentQueue<T>();
var queue = new ConcurrentQueue<T?>();
var backgroundReader = new BackgroundReader<T>(queue, new ClientReader(connection.Stream), readValue);
var backgroundProducer = new BackgroundProducer<T>(connection, _dispatcher, queue, callback);

Expand Down
2 changes: 1 addition & 1 deletion xunit.runner.wpf/Impl/TestAssemblyWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class TestAssemblyWatcher : ITestAssemblyWatcher
private readonly IDictionary<string, FileSystemWatcher> watchedAssemblies = new Dictionary<string, FileSystemWatcher>();
private readonly Dispatcher dispatcher;
private bool isEnabled = false;
private ReloadDebouncer debouncer;
private ReloadDebouncer? debouncer;

public TestAssemblyWatcher(Dispatcher dispatcher)
{
Expand Down
3 changes: 3 additions & 0 deletions xunit.runner.wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ public partial class MainWindow : Window
{
public static Window Instance { get; private set; }

// WPF generates fields that are marked as non-nullable, but not definitely initialized.
#pragma warning disable CS8618
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to be a problem if we have to do this for every single WPF control.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - see my mails to the LDM on the topic :-)

public MainWindow()
{
Instance = this;

InitializeComponent();
}
#pragma warning restore

protected override void OnSourceInitialized(EventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion xunit.runner.wpf/Persistence/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static partial class Storage

private static IsolatedStorageFile GetStorageFile() => IsolatedStorageFile.GetUserStoreForDomain();

public static XmlTextReader OpenXmlFile(string fileName)
public static XmlTextReader? OpenXmlFile(string fileName)
{
var storage = GetStorageFile();
if (!storage.FileExists(fileName))
Expand Down
4 changes: 2 additions & 2 deletions xunit.runner.wpf/ViewModel/AssemblyAndConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Xunit.Runner.Wpf.ViewModel
public class AssemblyAndConfigFile
{
public string AssemblyFileName { get; }
public string ConfigFileName { get; }
public string? ConfigFileName { get; }

public AssemblyAndConfigFile(string assemblyFileName, string configFileName)
public AssemblyAndConfigFile(string assemblyFileName, string? configFileName)
{
this.AssemblyFileName = Path.GetFullPath(assemblyFileName);
if (configFileName != null)
Expand Down
30 changes: 17 additions & 13 deletions xunit.runner.wpf/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MainViewModel : ViewModelBase

private CancellationTokenSource filterCancellationTokenSource = new CancellationTokenSource();

private CancellationTokenSource cancellationTokenSource;
private CancellationTokenSource? cancellationTokenSource;
private bool isBusy;
private SearchQuery searchQuery = new SearchQuery();
private bool autoReloadAssemblies;
Expand All @@ -54,7 +54,7 @@ public bool AutoReloadAssemblies

public ObservableCollection<RecentAssemblyViewModel> RecentAssemblies { get; } = new ObservableCollection<RecentAssemblyViewModel>();

private ImmutableList<TestCaseViewModel> testsToRun;
private ImmutableList<TestCaseViewModel>? testsToRun;

public ICommand ExitCommand { get; }
public ICommand WindowLoadedCommand { get; }
Expand All @@ -63,7 +63,6 @@ public bool AutoReloadAssemblies
public RelayCommand RunSelectedCommand { get; }
public RelayCommand CancelCommand { get; }
public ICommand TraitCheckedChangedCommand { get; }
public ICommand TraitSelectionChangedCommand { get; }
public ICommand TraitsClearCommand { get; }
public ICommand AssemblyReloadCommand { get; }
public ICommand AssemblyReloadAllCommand { get; }
Expand Down Expand Up @@ -215,8 +214,8 @@ public List<TestAssemblyViewModel> SelectedAssemblies
get { return Assemblies.Where(x => x.IsSelected).ToList(); }
}

private string testCasesCaption;
public string TestCasesCaption
private string? testCasesCaption;
public string? TestCasesCaption
{
get { return testCasesCaption; }
private set { Set(ref testCasesCaption, value); }
Expand All @@ -234,8 +233,8 @@ public int TestsCompleted
}
}

private TestCaseViewModel selectedTest;
public TestCaseViewModel SelectedTestCase
private TestCaseViewModel? selectedTest;
public TestCaseViewModel? SelectedTestCase
{
get { return selectedTest; }

Expand Down Expand Up @@ -401,7 +400,7 @@ await this.ExecuteTestSessionOperation(() =>
var taskList = new List<Task>();
foreach (var assembly in assemblies)
{
taskList.Add(this.testUtil.Discover(assembly.AssemblyFileName, this.OnTestsDiscovered, this.cancellationTokenSource.Token));
taskList.Add(this.testUtil.Discover(assembly.AssemblyFileName, this.OnTestsDiscovered, CancellationToken));

var assemblyViewModel = new TestAssemblyViewModel(assembly);

Expand All @@ -427,6 +426,11 @@ await this.ExecuteTestSessionOperation(() =>
}
}

private CancellationToken CancellationToken
=> cancellationTokenSource == null
? CancellationToken.None
: cancellationTokenSource.Token;

public bool ReloadAssemblies(IEnumerable<string> assemblies)
{
if (IsBusy)
Expand Down Expand Up @@ -454,7 +458,7 @@ await ExecuteTestSessionOperation(() =>
var assemblyFileName = assemblyViewModel.FileName;
RemoveAssemblyTestCases(assemblyFileName);

taskList.Add(this.testUtil.Discover(assemblyFileName, OnTestsDiscovered, cancellationTokenSource.Token));
taskList.Add(this.testUtil.Discover(assemblyFileName, OnTestsDiscovered, CancellationToken));
}

return taskList;
Expand Down Expand Up @@ -549,7 +553,7 @@ private IEnumerable<AssemblyAndConfigFile> ParseCommandLine(IEnumerable<string>
var assemblyFileName = enumerable.First();
enumerable = enumerable.Skip(1);

var configFileName = (string)null;
var configFileName = (string?)null;
if (IsConfigFile(enumerable.FirstOrDefault()))
{
configFileName = enumerable.First();
Expand Down Expand Up @@ -630,7 +634,7 @@ private List<Task> RunTests(ImmutableList<TestCaseViewModel> tests)
Task task;
if (runAll)
{
task = this.testUtil.RunAll(assemblyFileName, OnTestStateChange, this.cancellationTokenSource.Token);
task = this.testUtil.RunAll(assemblyFileName, OnTestStateChange, CancellationToken);
}
else
{
Expand All @@ -644,7 +648,7 @@ private List<Task> RunTests(ImmutableList<TestCaseViewModel> tests)
}
}

task = this.testUtil.RunSpecific(assemblyFileName, builder.ToImmutable(), OnTestStateChange, this.cancellationTokenSource.Token);
task = this.testUtil.RunSpecific(assemblyFileName, builder.ToImmutable(), OnTestStateChange, CancellationToken);
}

testSessionList.Add(task);
Expand Down Expand Up @@ -778,7 +782,7 @@ private bool CanExecuteCancel()
private void OnExecuteCancel()
{
Debug.Assert(CanExecuteCancel());
this.cancellationTokenSource.Cancel();
cancellationTokenSource?.Cancel();
}

private void OnExecuteTraitCheckedChanged(TraitViewModel trait)
Expand Down
4 changes: 2 additions & 2 deletions xunit.runner.wpf/ViewModel/TraitViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Xunit.Runner.Wpf.ViewModel
{
public partial class TraitViewModel : ViewModelBase
{
private readonly TraitViewModel _parent;
private readonly TraitViewModel? _parent;
private bool? _isChecked;
private bool _isExpanded;
private string _text;
Expand All @@ -19,7 +19,7 @@ public TraitViewModel(string text)
{
}

private TraitViewModel(TraitViewModel parent, string text)
private TraitViewModel(TraitViewModel? parent, string text)
{
this._parent = parent;
this._isChecked = false;
Expand Down
1 change: 0 additions & 1 deletion xunit.runner.wpf/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="2.2.0" targetFramework="net46" developmentDependency="true" />
<package id="MvvmLight" version="5.3.0.0" targetFramework="net46" />
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net46" />
<package id="NuGet.CommandLine" version="2.8.3" targetFramework="net46" />
Expand Down
2 changes: 0 additions & 2 deletions xunit.runner.wpf/xunit.runner.wpf.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.props" Condition="Exists('..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -216,7 +215,6 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.props'))" />
<Error Condition="!Exists('..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<Import Project="..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.targets" Condition="Exists('..\packages\Tvl.NuGet.BuildTasks.1.0.0-alpha002\build\Tvl.NuGet.BuildTasks.targets')" />
</Project>