Skip to content

Commit

Permalink
Fix warnings_not_as_errors order
Browse files Browse the repository at this point in the history
  • Loading branch information
purkhusid committed Apr 3, 2024
1 parent 8518611 commit 4438513
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dotnet/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ def generate_warning_args(
if len(warnings_as_errors) > 0:
fail("Cannot use both treat_warnings_as_errors and warnings_as_errors")

args.add("/warnaserror+")

for warning in warnings_not_as_errors:
args.add("/warnaserror-:{}".format(warning))

args.add("/warnaserror+")
else:
if len(warnings_not_as_errors) > 0:
fail("Cannot use warnings_not_as_errors if treat_warnings_as_errors is not set")
Expand Down
21 changes: 21 additions & 0 deletions dotnet/private/tests/warning_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//dotnet:defs.bzl", "csharp_library", "fsharp_library")
load(":csharp_warnings.bzl", "csharp_warnings")
load(":fsharp_warnings.bzl", "fsharp_warnings")

Expand Down Expand Up @@ -27,3 +28,23 @@ bzl_library(
"@bazel_skylib//lib:unittest",
],
)

# This is to test that the warnings are actually being ignored
csharp_library(
name = "csharp_ignore_warning",
srcs = ["lib_with_warning.cs"],
target_frameworks = ["net6.0"],
treat_warnings_as_errors = True,
warning_level = 4,
warnings_not_as_errors = ["CS1591"],
)

# This is to test that the warnings are actually being ignored
fsharp_library(
name = "fsharp_ignore_warning",
srcs = ["warnings.fs"],
target_frameworks = ["net6.0"],
treat_warnings_as_errors = True,
warning_level = 4,
warnings_not_as_errors = ["FS0025"],
)
16 changes: 16 additions & 0 deletions dotnet/private/tests/warning_settings/csharp_warnings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def csharp_warnings():
expected_partial_args = ["/warnaserror+"],
)

csharp_library(
name = "csharp_all_warnings_except_some",
srcs = ["warnings.cs"],
target_frameworks = ["net6.0"],
treat_warnings_as_errors = True,
warnings_not_as_errors = ["CS1591"],
tags = ["manual"],
)

action_args_test(
name = "csharp_all_warnings_except_some_test",
target_under_test = ":csharp_all_warnings_except_some",
action_mnemonic = "CSharpCompile",
expected_partial_args = ["/warnaserror+", "/warnaserror-:CS1591"],
)

csharp_library(
name = "csharp_warnings_as_errors",
srcs = ["warnings.cs"],
Expand Down
12 changes: 12 additions & 0 deletions dotnet/private/tests/warning_settings/lib_with_warning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Hello
{
public static class World
{
public static string HelloWorld()
{
return "Hello, world!";
}
}
}

0 comments on commit 4438513

Please sign in to comment.