vala-unit: Fix non-null build with newer vala

This commit is contained in:
Rico Tzschichholz 2023-04-14 09:42:23 +02:00
parent 4feb6b935e
commit 10f9c133a2
3 changed files with 18 additions and 18 deletions

View file

@ -256,7 +256,7 @@ internal class ValaUnit.ArrayCollectionAssertion<E> : GLib.Object,
public CollectionAssertions<E> contains(E expected) public CollectionAssertions<E> contains(E expected)
throws GLib.Error { throws GLib.Error {
E boxed_expected = box_value(expected); E? boxed_expected = box_value(expected);
bool found = false; bool found = false;
for (int i = 0; i < this.actual.length; i++) { for (int i = 0; i < this.actual.length; i++) {
try { try {
@ -281,7 +281,7 @@ internal class ValaUnit.ArrayCollectionAssertion<E> : GLib.Object,
public CollectionAssertions<E> not_contains(E expected) public CollectionAssertions<E> not_contains(E expected)
throws GLib.Error { throws GLib.Error {
E boxed_expected = box_value(expected); E? boxed_expected = box_value(expected);
for (int i = 0; i < this.actual.length; i++) { for (int i = 0; i < this.actual.length; i++) {
try { try {
assert_equal(box_value(this.actual[i]), boxed_expected); assert_equal(box_value(this.actual[i]), boxed_expected);
@ -312,8 +312,8 @@ internal class ValaUnit.ArrayCollectionAssertion<E> : GLib.Object,
this.context this.context
); );
} }
E boxed_actual = box_value(this.actual[index]); E? boxed_actual = box_value(this.actual[index]);
E boxed_expected = box_value(expected); E? boxed_expected = box_value(expected);
try { try {
assert_equal(boxed_actual, boxed_expected); assert_equal(boxed_actual, boxed_expected);
} catch (TestError.FAILED err) { } catch (TestError.FAILED err) {
@ -453,8 +453,8 @@ internal class ValaUnit.GeeCollectionAssertion<E> :
for (int i = 0; i <= index; i++) { for (int i = 0; i <= index; i++) {
iterator.next(); iterator.next();
} }
E boxed_actual = box_value(iterator.get()); E? boxed_actual = box_value(iterator.get());
E boxed_expected = box_value(expected); E? boxed_expected = box_value(expected);
try { try {
assert_equal(boxed_actual, boxed_expected); assert_equal(boxed_actual, boxed_expected);
} catch (TestError.FAILED err) { } catch (TestError.FAILED err) {

View file

@ -138,7 +138,7 @@ public interface ValaUnit.MockObject : GLib.Object, TestAssertions {
throws GLib.Error { throws GLib.Error {
assert_false(this.expected.is_empty, "Unexpected call: %s".printf(name)); assert_false(this.expected.is_empty, "Unexpected call: %s".printf(name));
ExpectedCall expected = this.expected.poll(); ExpectedCall expected = (!) this.expected.poll();
assert_equal(name, expected.name, "Unexpected call"); assert_equal(name, expected.name, "Unexpected call");
if (expected.expected_args != null) { if (expected.expected_args != null) {
assert_args(args, expected.expected_args, "Call %s".printf(name)); assert_args(args, expected.expected_args, "Call %s".printf(name));
@ -229,7 +229,7 @@ public interface ValaUnit.MockObject : GLib.Object, TestAssertions {
R default_return) R default_return)
throws GLib.Error { throws GLib.Error {
check_for_exception(expected); check_for_exception(expected);
R? return_object = default_return; R return_object = default_return;
if (expected.return_object != null) { if (expected.return_object != null) {
return_object = (R) expected.return_object; return_object = (R) expected.return_object;
} }
@ -243,7 +243,7 @@ public interface ValaUnit.MockObject : GLib.Object, TestAssertions {
if (expected.return_object == null) { if (expected.return_object == null) {
throw default_error; throw default_error;
} }
return expected.return_object; return (!) expected.return_object;
} }
private inline void check_for_exception(ExpectedCall expected) private inline void check_for_exception(ExpectedCall expected)

View file

@ -21,8 +21,8 @@ namespace ValaUnit {
} }
internal inline void assert_equal<T>(T actual, internal inline void assert_equal<T>(T? actual,
T expected, T? expected,
string? context = null) string? context = null)
throws TestError { throws TestError {
if ((actual == null && expected != null) || if ((actual == null && expected != null) ||
@ -107,9 +107,9 @@ namespace ValaUnit {
* *
* This will only work when the values are not already boxed. * This will only work when the values are not already boxed.
*/ */
internal T box_value<T>(T value) { internal T? box_value<T>(T value) {
var type = typeof(T); var type = typeof(T);
T boxed = value; T? boxed = value;
if (type == typeof(int) || type.is_enum()) { if (type == typeof(int) || type.is_enum()) {
int actual = (int) value; int actual = (int) value;
@ -133,7 +133,7 @@ namespace ValaUnit {
return boxed; return boxed;
} }
internal string to_display_string<T>(T value) { internal string to_display_string<T>(T? value) {
var type = typeof(T); var type = typeof(T);
var display = ""; var display = "";
@ -191,8 +191,8 @@ namespace ValaUnit {
); );
} }
private void assert_equal_enum<T>(T actual, private void assert_equal_enum<T>(T? actual,
T expected, T? expected,
string? context) string? context)
throws TestError { throws TestError {
int actual_val = (int) ((int?) actual); int actual_val = (int) ((int?) actual);
@ -342,7 +342,7 @@ public interface ValaUnit.TestAssertions : GLib.Object {
/** Asserts a value is null */ /** Asserts a value is null */
public void assert_non_null<T>(T actual, string? context = null) public void assert_non_null<T>(T? actual, string? context = null)
throws TestError { throws TestError {
if (actual == null) { if (actual == null) {
ValaUnit.assert( ValaUnit.assert(
@ -353,7 +353,7 @@ public interface ValaUnit.TestAssertions : GLib.Object {
} }
/** Asserts a value is null */ /** Asserts a value is null */
public void assert_is_null<T>(T actual, string? context = null) public void assert_is_null<T>(T? actual, string? context = null)
throws TestError { throws TestError {
if (actual != null) { if (actual != null) {
ValaUnit.assert( ValaUnit.assert(