Skip to content

Commit

Permalink
build: require NUnit 2.5
Browse files Browse the repository at this point in the history
Previous commit [1] stated something which is not always true
actually: although mono installs a mono-nunit.pc that contains
the mono version (as opposed to NUnit version), some distros
(like Debian/Ubuntu) have made that pc file be a symlink from
/usr/lib/pkg-config/mono-nunit.pc to /usr/lib/pkg-config/nunit-pc.

So the best thing is avoid this mess and only depend on NUnit,
which BTW brings some nice API since version 2.5 (mono embeds
version 2.4.8 [2]):

  Assert.That(actual, Is.EqualTo(expected));

This API is more readable (maps better to English language) and has
the added benefit of providing a way to never confuse again the
parameter *actual* with *expected* that was so easy to switch by
mistake on the older Assert.AreEqual(x,y) syntax.

Some lines are added to the HACKING file about this as well, and
the last test I wrote is converted to this syntax, as the first
real sample to have in the codebase.

[1] https://git.gnome.org/browse/banshee/commit/?id=3891ed1e5aaa7d06497525ab5bfc44110939a369
[2] https://github.com/mono/mono/blob/master/mcs/nunit24/CommonAssemblyInfo.cs
  • Loading branch information
knocte committed Jan 7, 2014
1 parent 3891ed1 commit 52166da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
5 changes: 5 additions & 0 deletions HACKING
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ guidelines. If code is in violation, you will be asked to reformat it.
12. Please write `private` accessors even if the language defaults
to it in the context you're in.

13. For tests, use the Assert.That(actual, Is.EqualTo(expected)); syntax,
which is more readable, and prevents you from misplacing the expected
parameter in the place of the actual parameter (a mistake that is very
usual when using the older Assert.AreEqual(,) syntax).


.NET API Naming Guidelines
==========================
Expand Down
11 changes: 1 addition & 10 deletions build/m4/shamrock/nunit.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
AC_DEFUN([SHAMROCK_CHECK_NUNIT],
[
NUNIT_REQUIRED=2.4.7
MONO_NUNIT_REQUIRED=2.4
AC_ARG_ENABLE(tests, AC_HELP_STRING([--enable-tests], [Enable NUnit tests]),
enable_tests=$enableval, enable_tests="no")
Expand All @@ -17,15 +16,7 @@ AC_DEFUN([SHAMROCK_CHECK_NUNIT],
AM_CONDITIONAL(ENABLE_TESTS, test "x$do_tests" = "xyes")
if test "x$do_tests" = "xno"; then
PKG_CHECK_MODULES(NUNIT, mono-nunit >= $MONO_NUNIT_REQUIRED,
do_tests="yes", do_tests="no")
AC_SUBST(NUNIT_LIBS)
AM_CONDITIONAL(ENABLE_TESTS, test "x$do_tests" = "xyes")
if test "x$do_tests" = "xno"; then
AC_MSG_WARN([Could not find nunit: tests will not be available])
fi
AC_MSG_WARN([Could not find nunit: tests will not be available])
fi
fi
])
8 changes: 4 additions & 4 deletions src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ private void UrisAreEquivalent (string expected, string actual)
string expected_without_querystring = expected.Substring (0, expected.IndexOf ("?"));
string actual_without_querystring = actual.Substring (0, actual.IndexOf ("?"));

Assert.AreEqual (expected_without_querystring, actual_without_querystring);
Assert.That (actual_without_querystring, Is.EqualTo (expected_without_querystring));

var expected_parameters = expected.Substring (expected.IndexOf ("?")).Split (new [] {'&'});
var actual_parameters = new List<string> (actual.Substring (actual.IndexOf ("?")).Split (new [] {'&'}));

Assert.AreEqual (expected_parameters.Length, actual_parameters.Count);
Assert.That (actual_parameters.Count, Is.EqualTo (expected_parameters.Length));
foreach (var expected_param in expected_parameters) {
Assert.IsTrue (actual_parameters.Contains (expected_param),
String.Format ("URI {0} is missing parameter '{1}'", actual, expected_param));
Assert.That (actual_parameters.Contains (expected_param),
String.Format ("URI {0} is missing parameter '{1}'", actual, expected_param));
}
}

Expand Down

0 comments on commit 52166da

Please sign in to comment.