Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit dd11908

Browse files
author
Stephen Hawley
committed
Slightly better asserts.
1 parent d3a7950 commit dd11908

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

tests/tom-swifty-test/Extensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using NUnit.Framework;
78
using SwiftReflector;
89

910
namespace tomwiftytest {
@@ -28,6 +29,16 @@ public static void CopyTo (this Stream stm, Stream source, int blockSize = 4096)
2829
break;
2930
}
3031
}
32+
33+
public static void AssertNoErrors (this ErrorHandling errors, string whileDoing)
34+
{
35+
Assert.IsFalse (errors.AnyErrors, $"{errors.ErrorCount} errors while {whileDoing}");
36+
}
37+
38+
public static void AssertNoWarnings (this ErrorHandling errors, string whileDoing)
39+
{
40+
Assert.IsTrue (errors.WarningCount == 0, $"{errors} errors while {whileDoing}");
41+
}
3142
}
3243
}
3344

tests/tom-swifty-test/SwiftReflector/BindingImportTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void LoadsDatabaseSmokeTest (PlatformName platform, int expectedLowerLimi
2323
var database = importer.Import ();
2424
Assert.IsNotNull (database, $"null database for {platform}");
2525
Assert.Less (expectedLowerLimit, database.Count, $"Expected at least {expectedLowerLimit} db entries, but got {database.Count} entries.");
26-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
26+
errors.AssertNoErrors ("errors importing database.");
2727
}
2828

2929
[TestCase (PlatformName.iOS)]
@@ -39,7 +39,7 @@ public void HasAtLeastNSObject (PlatformName platform)
3939
Assert.IsNotNull (entity, $"Didn't get an NSObject from database on {platform}");
4040
Assert.IsTrue (entity.IsObjCClass, $"NSObject is not an ObjC class on {platform}. Seriously?");
4141
Assert.IsNotNull (entity.Type, $"No type in NSObject on {platform}");
42-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
42+
errors.AssertNoErrors ("errors importing database.");
4343
}
4444

4545
[Test]
@@ -50,7 +50,7 @@ public void ExcludesEverything ()
5050
importer.Excludes.Add (new PatternMatch (".*"));
5151
var database = importer.Import ();
5252
Assert.AreEqual (0, database.Count, $"This was supposed to exclude everything, but we got {database.Count} entries.");
53-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
53+
errors.AssertNoErrors ("errors importing database.");
5454
}
5555

5656

@@ -63,7 +63,7 @@ public void ReincludesNSObject()
6363
importer.Includes.Add (new PatternMatch ("Foundation\\.NSObject"));
6464
var database = importer.Import ();
6565
Assert.AreEqual (1, database.Count, $"This was supposed to exclude everything, but we got {database.Count} entries.");
66-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
66+
errors.AssertNoErrors ("errors importing database.");
6767
}
6868

6969

@@ -77,7 +77,7 @@ public void ReincludesFoundation ()
7777
importer.Includes.Add (new PatternMatch ("Foundation\\..*"));
7878
var database = importer.Import ();
7979
Assert.Less (175, database.Count, $"This was supposed to exclude everything, but we got {database.Count} entries.");
80-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
80+
errors.AssertNoErrors ("errors importing database.");
8181
}
8282

8383

@@ -93,8 +93,7 @@ public void LoadsIUIViewControllerTransitionCoordinator (PlatformName platform)
9393
Assert.IsNotNull (entity, $"Didn't get an IUIViewControllerTransitionCoordinator from database on {platform}");
9494
Assert.IsTrue (entity.IsObjCProtocol, $"NSObject is not an ObjC protocol on {platform}. Seriously?");
9595
Assert.IsNotNull (entity.Type, $"No type in IUIViewControllerTransitionCoordinator on {platform}");
96-
Assert.IsTrue (!errors.AnyErrors, $"{errors.ErrorCount} errors importing database.");
97-
96+
errors.AssertNoErrors ("errors importing database.");
9897
}
9998
}
10099
}

0 commit comments

Comments
 (0)