Skip to content

Commit

Permalink
Merge pull request #979 from adamralph/lang-versions-warnings
Browse files Browse the repository at this point in the history
update lang versions and address warnings
  • Loading branch information
adamralph authored Jul 21, 2024
2 parents 31f8ab0 + de20570 commit 2a6028f
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 97 deletions.
2 changes: 2 additions & 0 deletions Bullseye/Bullseye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/adamralph/bullseye/blob/main/CHANGELOG.md</PackageReleaseNotes>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- remove together with net6.0 -->
<NoWarn>IDE0028;IDE0301</NoWarn>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

Expand Down
36 changes: 18 additions & 18 deletions Bullseye/Internal/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Bullseye.Internal;

#if NET6_0
internal static class NativeMethods
#else
#if NET8_0_OR_GREATER
internal static partial class NativeMethods
#else
internal static class NativeMethods
#endif
{
[Flags]
Expand All @@ -19,35 +19,35 @@ public enum StdHandle
STD_OUTPUT_HANDLE = -11,
}

#if NET6_0
[DllImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern IntPtr GetStdHandle(StdHandle nStdHandle);
#else
#if NET8_0_OR_GREATER
[LibraryImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static partial nint GetStdHandle(StdHandle nStdHandle);
#endif

#if NET6_0
#else
[DllImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern bool GetConsoleMode(nint hConsoleHandle, out ConsoleOutputModes lpMode);
#else
public static extern IntPtr GetStdHandle(StdHandle nStdHandle);
#endif

#if NET8_0_OR_GREATER
[LibraryImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool GetConsoleMode(nint hConsoleHandle, out ConsoleOutputModes lpMode);
#endif

#if NET6_0
#else
[DllImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern bool SetConsoleMode(nint hConsoleHandle, ConsoleOutputModes dwMode);
#else
public static extern bool GetConsoleMode(nint hConsoleHandle, out ConsoleOutputModes lpMode);
#endif

#if NET8_0_OR_GREATER
[LibraryImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool SetConsoleMode(nint hConsoleHandle, ConsoleOutputModes dwMode);
#else
[DllImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern bool SetConsoleMode(nint hConsoleHandle, ConsoleOutputModes dwMode);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net8.0</TargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion BullseyeSmokeTester.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#pragma warning restore IDE0028
foreach (var (aliases, description) in Options.Definitions)
{
cmd.Add(new Option<bool>(aliases.ToArray(), description));
cmd.Add(new Option<bool>([.. aliases,], description));
}

cmd.SetHandler(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net8.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net8.0</TargetFramework>
Expand Down
1 change: 1 addition & 0 deletions BullseyeSmokeTester/BullseyeSmokeTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net8.0</TargetFramework>
Expand Down
1 change: 1 addition & 0 deletions BullseyeTests/BullseyeTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>default</LangVersion>
<RollForward>major</RollForward>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions BullseyeTests/CaseInsensitivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public static async Task MixingCase()
var targets = new TargetCollection
{
CreateTarget("first", () => first = true),
CreateTarget("second", new[] { "FIRST", }, () => second = true),
CreateTarget("second", ["FIRST",], () => second = true),
};

// act
await targets.RunAsync(new[] { "SECOND", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["SECOND",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.True(first);
Expand Down
8 changes: 4 additions & 4 deletions BullseyeTests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public static void ParseShortNames()
Assert.True(result.Options.Verbose);

Assert.True(result.ShowHelp);
Assert.Equal(new[] { "target0", "target1", }, result.Targets);
Assert.Equal(new[] { "-0", "-1", }, result.UnknownOptions);
Assert.Equal(["target0", "target1",], result.Targets);
Assert.Equal(["-0", "-1",], result.UnknownOptions);
}

[Fact]
Expand Down Expand Up @@ -123,7 +123,7 @@ public static void ParseLongNames()
Assert.True(result.Options.Verbose);

Assert.True(result.ShowHelp);
Assert.Equal(new[] { "target0", "target1", }, result.Targets);
Assert.Equal(new[] { "--unknown0", "--unknown1", }, result.UnknownOptions);
Assert.Equal(["target0", "target1",], result.Targets);
Assert.Equal(["--unknown0", "--unknown1",], result.UnknownOptions);
}
}
62 changes: 29 additions & 33 deletions BullseyeTests/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

namespace BullseyeTests;

#if NET8_0_OR_GREATER
public static partial class Dependencies
#else
public static class Dependencies
#endif
{
[Fact]
public static async Task FlatDependencies()
Expand All @@ -21,11 +17,11 @@ public static async Task FlatDependencies()
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", () => ran.Add("second")),
CreateTarget("third", new[] { "first", "second", }, () => ran.Add("third")),
CreateTarget("third", ["first", "second",], () => ran.Add("third")),
};

// act
await targets.RunAsync(new List<string> { "third", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["third",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(3, ran.Count);
Expand All @@ -43,12 +39,12 @@ public static async Task NestedDependencies()
var targets = new TargetCollection
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", new[] { "first", }, () => ran.Add("second")),
CreateTarget("third", new[] { "second", }, () => ran.Add("third")),
CreateTarget("second", ["first",], () => ran.Add("second")),
CreateTarget("third", ["second",], () => ran.Add("third")),
};

// act
await targets.RunAsync(new List<string> { "third", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["third",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(3, ran.Count);
Expand All @@ -66,11 +62,11 @@ public static async Task DoubleDependency()
var targets = new TargetCollection
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", new[] { "first", "first", }, () => ran.Add("second")),
CreateTarget("second", ["first", "first",], () => ran.Add("second")),
};

// act
await targets.RunAsync(new List<string> { "second", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["second",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(2, ran.Count);
Expand All @@ -84,11 +80,11 @@ public static async Task SelfDependency()
// arrange
var targets = new TargetCollection
{
CreateTarget("first", new[] { "first", }),
CreateTarget("first", ["first",]),
};

// act
var exception = await Record.ExceptionAsync(() => targets.RunAsync(new List<string> { "first", }, _ => false, () => "", Console.Out, Console.Error, false));
var exception = await Record.ExceptionAsync(() => targets.RunAsync(["first",], _ => false, () => "", Console.Out, Console.Error, false));

// assert
Assert.NotNull(exception);
Expand All @@ -101,12 +97,12 @@ public static async Task MutualDependency()
// arrange
var targets = new TargetCollection
{
CreateTarget("first", new[] { "second", }),
CreateTarget("second", new[] { "first", }),
CreateTarget("first", ["second",]),
CreateTarget("second", ["first",]),
};

// act
var exception = await Record.ExceptionAsync(() => targets.RunAsync(new List<string> { "second", }, _ => false, () => "", Console.Out, Console.Error, false));
var exception = await Record.ExceptionAsync(() => targets.RunAsync(["second",], _ => false, () => "", Console.Out, Console.Error, false));

// assert
Assert.NotNull(exception);
Expand All @@ -119,13 +115,13 @@ public static async Task CircularDependency()
// arrange
var targets = new TargetCollection
{
CreateTarget("first", new[] { "third", }),
CreateTarget("second", new[] { "first", }),
CreateTarget("third", new[] { "second", }),
CreateTarget("first", ["third",]),
CreateTarget("second", ["first",]),
CreateTarget("third", ["second",]),
};

// act
var exception = await Record.ExceptionAsync(() => targets.RunAsync(new List<string> { "third", }, _ => false, () => "", Console.Out, Console.Error, false));
var exception = await Record.ExceptionAsync(() => targets.RunAsync(["third",], _ => false, () => "", Console.Out, Console.Error, false));

// assert
Assert.NotNull(exception);
Expand All @@ -143,12 +139,12 @@ public static async Task DoubleTransitiveDependency()
var targets = new TargetCollection
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", new[] { "first", }, () => ran.Add("second")),
CreateTarget("third", new[] { "first", "second", }, () => ran.Add("third")),
CreateTarget("second", ["first",], () => ran.Add("second")),
CreateTarget("third", ["first", "second",], () => ran.Add("third")),
};

// act
await targets.RunAsync(new List<string> { "third", "--no-color", "--verbose", }, _ => false, () => "", outputWriter, Console.Error, false);
await targets.RunAsync(["third", "--no-color", "--verbose",], _ => false, () => "", outputWriter, Console.Error, false);

// assert
var output = outputWriter.ToString();
Expand Down Expand Up @@ -184,12 +180,12 @@ public static async Task NotExistentDependencies()
var targets = new TargetCollection
{
CreateTarget("first", () => anyRan = true),
CreateTarget("second", new[] { "first", "non-existing", }, () => anyRan = true),
CreateTarget("third", new[] { "second", "also-non-existing", }, () => anyRan = true),
CreateTarget("second", ["first", "non-existing",], () => anyRan = true),
CreateTarget("third", ["second", "also-non-existing",], () => anyRan = true),
};

// act
var exception = await Record.ExceptionAsync(() => targets.RunAsync(new List<string> { "third", }, _ => false, () => "", Console.Out, Console.Error, false));
var exception = await Record.ExceptionAsync(() => targets.RunAsync(["third",], _ => false, () => "", Console.Out, Console.Error, false));

// assert
Assert.NotNull(exception);
Expand All @@ -207,11 +203,11 @@ public static async Task SkippingDependencies()
var targets = new TargetCollection
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", new[] { "first", "non-existent", }, () => ran.Add("second")),
CreateTarget("second", ["first", "non-existent",], () => ran.Add("second")),
};

// act
await targets.RunAsync(new List<string> { "second", "-s", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["second", "-s",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Contains("second", ran);
Expand All @@ -227,11 +223,11 @@ public static async Task DependencyOrderWhenSkipping()
var targets = new TargetCollection
{
CreateTarget("first", () => ran.Add("first")),
CreateTarget("second", new[] { "first", }, () => ran.Add("second")),
CreateTarget("second", ["first",], () => ran.Add("second")),
};

// act
await targets.RunAsync(new List<string> { "--skip-dependencies", "second", "first", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["--skip-dependencies", "second", "first",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(2, ran.Count);
Expand All @@ -255,12 +251,12 @@ public static async Task DependencyOrderWhenParallelAndSkipping()
Thread.Sleep(TimeSpan.FromSeconds(1)); // a weak way to encourage the tests to run first
buildStartTime = Interlocked.Increment(ref clock);
}),
CreateTarget("test1", new[] { "build", }, () => test1StartTime = Interlocked.Increment(ref clock)),
CreateTarget("test2", new[] { "build", }, () => test2StartTime = Interlocked.Increment(ref clock)),
CreateTarget("test1", ["build",], () => test1StartTime = Interlocked.Increment(ref clock)),
CreateTarget("test2", ["build",], () => test2StartTime = Interlocked.Increment(ref clock)),
};

// act
await targets.RunAsync(new List<string> { "--parallel", "--skip-dependencies", "test1", "test2", "build", }, _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync(["--parallel", "--skip-dependencies", "test1", "test2", "build",], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(1, buildStartTime);
Expand Down
4 changes: 2 additions & 2 deletions BullseyeTests/EnumerableInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task WithInputs()
};

// act
await targets.RunAsync(new List<string>(), _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync([], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.Equal(2, inputsReceived.Count);
Expand All @@ -38,7 +38,7 @@ public static async Task WithoutInputs()
};

// act
await targets.RunAsync(new List<string>(), _ => false, () => "", Console.Out, Console.Error, false);
await targets.RunAsync([], _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.False(ran);
Expand Down
4 changes: 2 additions & 2 deletions BullseyeTests/Infra/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BullseyeTests.Infra;

internal static class Helper
{
public static Target CreateTarget(string name, Action action) => CreateTarget(name, Array.Empty<string>(), action);
public static Target CreateTarget(string name, Action action) => CreateTarget(name, [], action);

public static Target CreateTarget(string name, IEnumerable<string> dependencies, Action action) =>
new ActionTarget(name, "", dependencies, action.ToAsync());
Expand All @@ -13,5 +13,5 @@ public static Target CreateTarget(string name, IEnumerable<string> dependencies)
new(name, "", dependencies);

public static Target CreateTarget<TInput>(string name, IEnumerable<TInput> forEach, Action<TInput> action) =>
new ActionTarget<TInput>(name, "", Array.Empty<string>(), forEach, action.ToAsync());
new ActionTarget<TInput>(name, "", [], forEach, action.ToAsync());
}
Loading

0 comments on commit 2a6028f

Please sign in to comment.