Author: spouliot
Date: 2008-02-15 13:12:17 -0500 (Fri, 15 Feb 2008)
New Revision: 95775
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ChangeLog
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewExceptionWithoutThrowingTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewThreadWithoutStartTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CloneMethodShouldNotReturnNullTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ConstructorShouldNotCallVirtualMethodsTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/EqualShouldHandleNullArgTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/GetEntryAssemblyMayReturnNullTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ToStringReturnsNullTest.cs
Log:
2008-02-15 Sebastien Pouliot <[EMAIL PROTECTED]>
* CheckNewExceptionWithoutThrowingTest.cs
* CheckNewThreadWithoutStartTest.cs
* CloneMethodShouldNotReturnNullTest.cs
* ConstructorShouldNotCallVirtualMethodsTest.cs
* EqualShouldHandleNullArgTest.cs
* GetEntryAssemblyMayReturnNullTest.cs
* ToStringReturnsNullTest.cs
Update unit tests wrt framework changes.
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ChangeLog
2008-02-15 18:11:53 UTC (rev 95774)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ChangeLog
2008-02-15 18:12:17 UTC (rev 95775)
@@ -1,3 +1,14 @@
+2008-02-15 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * CheckNewExceptionWithoutThrowingTest.cs
+ * CheckNewThreadWithoutStartTest.cs
+ * CloneMethodShouldNotReturnNullTest.cs
+ * ConstructorShouldNotCallVirtualMethodsTest.cs
+ * EqualShouldHandleNullArgTest.cs
+ * GetEntryAssemblyMayReturnNullTest.cs
+ * ToStringReturnsNullTest.cs
+ Update unit tests wrt framework changes.
+
2008-01-30 Sebastien Pouliot <[EMAIL PROTECTED]>
* CheckNewExceptionWithoutThrowingTest.cs: New. Unit tests by
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewExceptionWithoutThrowingTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewExceptionWithoutThrowingTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewExceptionWithoutThrowingTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -3,8 +3,10 @@
//
// Authors:
// Andreas Noever <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2008 Andreas Noever
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -43,6 +45,7 @@
private AssemblyDefinition assembly;
private TypeDefinition type;
private CheckNewExceptionWithoutThrowingRule rule;
+ private TestRunner runner;
[TestFixtureSetUp]
public void FixtureSetUp ()
@@ -51,6 +54,7 @@
assembly = AssemblyFactory.GetAssembly (unit);
type = assembly.MainModule.Types
["Test.Rules.BadPractice.CheckNewExceptionWithoutThrowingTest"];
rule = new CheckNewExceptionWithoutThrowingRule ();
+ runner = new TestRunner (rule);
}
public MethodDefinition GetTest (string name)
@@ -72,7 +76,8 @@
public void TestDirectThrow ()
{
MethodDefinition method = GetTest ("DirectThrow");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void SimpleError ()
@@ -84,7 +89,8 @@
public void TestSimpleError ()
{
MethodDefinition method = GetTest ("SimpleError");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public void LocalVariable ()
@@ -100,7 +106,8 @@
public void TestLocalVariable ()
{
MethodDefinition method = GetTest ("LocalVariable");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public object Return ()
@@ -114,7 +121,8 @@
public void TestReturn ()
{
MethodDefinition method = GetTest ("Return");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public object ReturnOther ()
@@ -129,7 +137,8 @@
public void TestReturnOther ()
{
MethodDefinition method = GetTest ("ReturnOther");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public object Branch ()
@@ -145,7 +154,8 @@
public void TestBranch ()
{
MethodDefinition method = GetTest ("Branch");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void TryCatch ()
@@ -166,7 +176,8 @@
public void TestTryCatch ()
{
MethodDefinition method = GetTest ("TryCatch");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void TryCatch2 ()
@@ -188,7 +199,8 @@
public void TestTryCatch2 ()
{
MethodDefinition method = GetTest ("TryCatch2");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
@@ -211,7 +223,8 @@
public void TestTryCatchFinally ()
{
MethodDefinition method = GetTest ("TryCatchFinally");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void Out (out Exception ex)
@@ -223,7 +236,8 @@
public void TestOut ()
{
MethodDefinition method = GetTest ("Out");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void Ref (ref Exception ex)
@@ -235,7 +249,8 @@
public void TestRef ()
{
MethodDefinition method = GetTest ("Ref");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
@@ -249,7 +264,8 @@
public void TestCall ()
{
MethodDefinition method = GetTest ("Call");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public void Call2 ()
@@ -262,7 +278,8 @@
public void TestCall2 ()
{
MethodDefinition method = GetTest ("Call2");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
}
}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewThreadWithoutStartTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewThreadWithoutStartTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CheckNewThreadWithoutStartTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -3,8 +3,10 @@
//
// Authors:
// Andreas Noever <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2008 Andreas Noever
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -44,6 +46,7 @@
private AssemblyDefinition assembly;
private TypeDefinition type;
private CheckNewThreadWithoutStartRule rule;
+ private TestRunner runner;
[TestFixtureSetUp]
public void FixtureSetUp ()
@@ -52,6 +55,7 @@
assembly = AssemblyFactory.GetAssembly (unit);
type = assembly.MainModule.Types
["Test.Rules.BadPractice.CheckNewThreadWithoutStartTest"];
rule = new CheckNewThreadWithoutStartRule ();
+ runner = new TestRunner (rule);
}
public MethodDefinition GetTest (string name)
@@ -74,10 +78,10 @@
public void TestDirectThrow ()
{
MethodDefinition method = GetTest ("DirectStart");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
-
public void SimpleError ()
{
new Thread (ThreadStart);
@@ -87,7 +91,8 @@
public void TestSimpleError ()
{
MethodDefinition method = GetTest ("SimpleError");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public void LocalVariable ()
@@ -103,11 +108,10 @@
public void TestLocalVariable ()
{
MethodDefinition method = GetTest ("LocalVariable");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
-
-
public object Return ()
{
Thread a = new Thread (ThreadStart);
@@ -119,7 +123,8 @@
public void TestReturn ()
{
MethodDefinition method = GetTest ("Return");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public object ReturnOther ()
@@ -134,7 +139,8 @@
public void TestReturnOther ()
{
MethodDefinition method = GetTest ("ReturnOther");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public object Branch ()
@@ -150,7 +156,8 @@
public void TestBranch ()
{
MethodDefinition method = GetTest ("Branch");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public Thread TryCatch ()
@@ -171,7 +178,8 @@
public void TestTryCatch ()
{
MethodDefinition method = GetTest ("TryCatch");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public Thread TryCatch2 ()
@@ -194,10 +202,10 @@
public void TestTryCatch2 ()
{
MethodDefinition method = GetTest ("TryCatch2");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
-
public void TryCatchFinally ()
{
Thread a = new Thread (ThreadStart);
@@ -217,7 +225,8 @@
public void TestTryCatchFinally ()
{
MethodDefinition method = GetTest ("TryCatchFinally");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void Out (out Thread thread)
@@ -229,7 +238,8 @@
public void TestOut ()
{
MethodDefinition method = GetTest ("Out");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
public void Ref (ref Thread thread)
@@ -241,10 +251,10 @@
public void TestRef ()
{
MethodDefinition method = GetTest ("Ref");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
-
public void Call ()
{
Thread a = new Thread (ThreadStart);
@@ -256,7 +266,8 @@
public void TestCall ()
{
MethodDefinition method = GetTest ("Call");
- Assert.IsNotNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
public void Call2 ()
@@ -269,7 +280,8 @@
public void TestCall2 ()
{
MethodDefinition method = GetTest ("Call2");
- Assert.IsNull (rule.CheckMethod (method, new
MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
}
}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CloneMethodShouldNotReturnNullTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CloneMethodShouldNotReturnNullTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/CloneMethodShouldNotReturnNullTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -3,8 +3,10 @@
//
// Authors:
// Nidhi Rawal <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// Copyright (c) <2007> Nidhi Rawal
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
deal
@@ -93,18 +95,18 @@
}
}
- private ITypeRule typeRule;
+ private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
private TypeDefinition type;
- MessageCollection messageCollection;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- typeRule = new CloneMethodShouldNotReturnNullRule ();
- messageCollection = null;
+ rule = new CloneMethodShouldNotReturnNullRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -117,42 +119,40 @@
public void cloneMethodReturningNullTest ()
{
type = GetTest ("CloneMethodReturningNull");
- messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
- Assert.IsNotNull (messageCollection);
- Assert.AreEqual (1, messageCollection.Count);
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void cloneMethodNotReturningNullTest ()
{
type = GetTest ("CloneMethodNotReturningNull");
- messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
- Assert.IsNull (messageCollection);
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void notUsingICloneableCloneTest ()
{
type = GetTest ("NotUsingICloneableClone");
- messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
- Assert.IsNull (messageCollection);
+ Assert.AreEqual (RuleResult.DoesNotApply,
runner.CheckType (type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void cloneWithDifferentArgsReturningNullTest ()
{
type = GetTest ("CloneWithDifferentArgsReturningNull");
- messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
- Assert.IsNull (messageCollection);
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void cloneReturningNullInSomeConditionsTest ()
{
type = GetTest ("CloneReturningNullInSomeConditions");
- messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
- Assert.IsNotNull (messageCollection);
- Assert.AreEqual (1, messageCollection.Count);
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
}
-}
\ No newline at end of file
+}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ConstructorShouldNotCallVirtualMethodsTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ConstructorShouldNotCallVirtualMethodsTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ConstructorShouldNotCallVirtualMethodsTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -240,7 +240,7 @@
private ITypeRule rule;
private AssemblyDefinition assembly;
- private Runner runner;
+ private TestRunner runner;
[TestFixtureSetUp]
@@ -249,7 +249,7 @@
string unit =
System.Reflection.Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new ConstructorShouldNotCallVirtualMethodsRule
();
- runner = new MinimalRunner ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest<T> ()
@@ -257,101 +257,108 @@
return assembly.MainModule.Types [typeof (T).FullName];
}
-
[Test]
public void TestClassWithStaticCtor ()
{
- Assert.IsNull (rule.CheckType
(GetTest<ClassWithStaticCtor> (), runner));
+ TypeDefinition type = GetTest<ClassWithStaticCtor> ();
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestSealedClassWithVirtualCall ()
{
- Assert.IsNull (rule.CheckType
(GetTest<SealedClassWithVirtualCall> (), runner));
+ TypeDefinition type =
GetTest<SealedClassWithVirtualCall> ();
+ Assert.AreEqual (RuleResult.DoesNotApply,
runner.CheckType (type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestClassWithInstanceOfItself ()
{
- Assert.IsNull (rule.CheckType
(GetTest<ClassWithInstanceOfItself> (), runner));
+ TypeDefinition type =
GetTest<ClassWithInstanceOfItself> ();
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestClassCallingVirtualMethodOnce ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassCallingVirtualMethodOnce> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassCallingVirtualMethodOnce> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void TestClassCallingVirtualMethodThreeTimes ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassCallingVirtualMethodThreeTimes> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (3, messages.Count);
+ TypeDefinition type =
GetTest<ClassCallingVirtualMethodThreeTimes> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (3, runner.Defects.Count, "Count");
}
[Test]
public void TestClassNotCallingVirtualMethods ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassNotCallingVirtualMethods> (), runner);
- Assert.IsNull (messages);
+ TypeDefinition type =
GetTest<ClassNotCallingVirtualMethods> ();
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestClassCallingVirtualMethodFromBaseClass ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassCallingVirtualMethodFromBaseClass> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassCallingVirtualMethodFromBaseClass> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void TestClassCallingVirtualPropertyFromBaseClass ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassCallingVirtualPropertyFromBaseClass> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassCallingVirtualPropertyFromBaseClass> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void TestClassIndirectlyCallingVirtualMethod ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassIndirectlyCallingVirtualMethod> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassIndirectlyCallingVirtualMethod> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void
TestClassIndirectlyCallingVirtualMethodFromBaseClass ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassIndirectlyCallingVirtualMethodFromBaseClass> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassIndirectlyCallingVirtualMethodFromBaseClass> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void
TestClassIndirectlyCallingVirtualPropertyFromBaseClass ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassIndirectlyCallingVirtualPropertyFromBaseClass> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassIndirectlyCallingVirtualPropertyFromBaseClass> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void TestClassCallingVirtualMethodFromOtherClasses ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassCallingVirtualMethodFromOtherClasses> (), runner);
- Assert.IsNull (messages);
+ TypeDefinition type =
GetTest<ClassCallingVirtualMethodFromOtherClasses> ();
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestClassWithRecursiveVirtualCall ()
{
- MessageCollection messages = rule.CheckType
(GetTest<ClassWithRecursiveVirtualCall> (), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ TypeDefinition type =
GetTest<ClassWithRecursiveVirtualCall> ();
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
}
}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/EqualShouldHandleNullArgTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/EqualShouldHandleNullArgTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/EqualShouldHandleNullArgTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -180,7 +180,7 @@
private ITypeRule rule;
private AssemblyDefinition assembly;
private TypeDefinition type;
- private Runner runner;
+ private TestRunner runner;
[TestFixtureSetUp]
public void FixtureSetUp ()
@@ -188,7 +188,7 @@
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new EqualShouldHandleNullArgRule ();
- runner = new MinimalRunner ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -201,48 +201,56 @@
public void equalsChecksForNullArgTest ()
{
type = GetTest ("EqualsChecksForNullArg");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void equalsDoesNotReturnFalseForNullArgTest ()
{
type = GetTest ("EqualsDoesNotReturnFalseForNullArg");
- Assert.IsNotNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void equalsNotOverriddenNotCheckingNullTest ()
{
type = GetTest ("EqualsNotOverriddenNotCheckingNull");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void equalsNotOverriddenNotReturningFalseForNullTest ()
{
type = GetTest
("EqualsNotOverriddenNotReturningFalseForNull");
- Assert.IsNotNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void EqualsReturnConstant ()
{
type = GetTest ("EqualsReturnsFalse");
- Assert.IsNull (rule.CheckType (type, runner),
"EqualsReturnsFalse");
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
type = GetTest ("EqualsReturnsTrue");
- Assert.IsNotNull (rule.CheckType (type, runner),
"EqualsReturnsTrue");
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void EqualsUsingIs ()
{
type = GetTest ("EqualsUsingIsReturnFalse");
- Assert.IsNull (rule.CheckType (type, runner),
"EqualsUsingIsReturnFalse");
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
type = GetTest ("EqualsUsingIsReturnTrue");
- Assert.IsNotNull (rule.CheckType (type, runner),
"EqualsUsingIsReturnTrue");
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
@@ -250,21 +258,24 @@
{
type = GetTest ("EqualsCallBase");
// we can't be sure so we shut up (else false positives
gets really bad)
- Assert.IsNull (rule.CheckType (type, runner),
"EqualsCallBase");
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void EqualsCheckThisTest ()
{
type = GetTest ("EqualsCheckThis");
- Assert.IsNull (rule.CheckType (type, runner),
"EqualsCheckThis");
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void EqualsCheckTypeTest ()
{
type = GetTest ("EqualsCheckType");
- Assert.IsNull (rule.CheckType (type, runner),
"EqualsCheckType");
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
}
}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/GetEntryAssemblyMayReturnNullTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/GetEntryAssemblyMayReturnNullTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/GetEntryAssemblyMayReturnNullTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -3,8 +3,10 @@
//
// Authors:
// Daniel Abramov <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// Copyright (C) Daniel Abramov
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
deal
@@ -69,7 +71,7 @@
private IMethodRule rule;
private AssemblyDefinition assembly;
- private Runner runner;
+ private TestRunner runner;
[TestFixtureSetUp]
@@ -78,7 +80,7 @@
string unit =
System.Reflection.Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new GetEntryAssemblyMayReturnNullRule ();
- runner = new MinimalRunner ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest<T> ()
@@ -89,35 +91,41 @@
[Test]
public void TestMethodNotCallingGetEntryAssembly ()
{
- MessageCollection messages = rule.CheckMethod
(GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("NoCalls", new
Type [] { }), runner);
- Assert.IsNull (messages);
+ MethodDefinition method =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("NoCalls", new Type
[] { });
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void TestGetEntryAssemblyCallFromExecutable ()
{
- assembly.EntryPoint =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("Main", new Type []
{ });
- assembly.Kind = AssemblyKind.Console;
- MessageCollection messages = rule.CheckMethod
(GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("ThreeCalls", new
Type [] { }), runner);
- Assert.IsNull (messages);
- assembly.EntryPoint = null;
- assembly.Kind = AssemblyKind.Dll;
+ try {
+ assembly.EntryPoint =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("Main", new Type []
{ });
+ assembly.Kind = AssemblyKind.Console;
+ MethodDefinition method =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("ThreeCalls", new
Type [] { });
+ Assert.AreEqual (RuleResult.DoesNotApply,
runner.CheckMethod (method), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count,
"Count");
+ }
+ finally {
+ assembly.EntryPoint = null;
+ assembly.Kind = AssemblyKind.Dll;
+ }
}
[Test]
public void TestMethodCallingGetEntryAssemblyOnce ()
{
- MessageCollection messages = rule.CheckMethod
(GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("OneCall", new
Type [] { }), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ MethodDefinition method =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("OneCall", new Type
[] { });
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void TestMethodCallingGetEntryAssemblyThreeTimes ()
{
- MessageCollection messages = rule.CheckMethod
(GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("ThreeCalls", new
Type [] { }), runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (3, messages.Count);
+ MethodDefinition method =
GetTest<ClassCallingGetEntryAssembly> ().Methods.GetMethod ("ThreeCalls", new
Type [] { });
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod
(method), "RuleResult");
+ Assert.AreEqual (3, runner.Defects.Count, "Count");
}
}
}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ToStringReturnsNullTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ToStringReturnsNullTest.cs
2008-02-15 18:11:53 UTC (rev 95774)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.BadPractice/Test/ToStringReturnsNullTest.cs
2008-02-15 18:12:17 UTC (rev 95775)
@@ -120,7 +120,7 @@
private ITypeRule rule;
private AssemblyDefinition assembly;
private TypeDefinition type;
- private MinimalRunner runner;
+ private TestRunner runner;
[TestFixtureSetUp]
public void FixtureSetUp ()
@@ -128,7 +128,7 @@
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new ToStringReturnsNullRule ();
- runner = new MinimalRunner ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -141,14 +141,16 @@
public void ReturningNullTest ()
{
type = GetTest ("ToStringReturningNull");
- Assert.IsNotNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void ReturningEmptyStringTest ()
{
type = GetTest ("ToStringReturningEmptyString");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
@@ -156,35 +158,40 @@
{
type = GetTest ("ToStringReturningField");
// there's doubt but it's not easy (i.e. false
positives) to be sure
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void ReturningConstField ()
{
type = GetTest ("ToStringReturningConstField");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void ReturningReadOnlyField ()
{
type = GetTest ("ToStringReturningReadOnlyField");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void ReturningNewString ()
{
type = GetTest ("ToStringReturningNewString");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
public void ReturningStringFormat ()
{
type = GetTest ("ToStringReturningStringFormat");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
@@ -192,7 +199,8 @@
{
Assert.AreEqual (String.Empty, Convert.ToString
((object) null), "Convert.ToString(object)");
type = GetTest
("ToStringReturningConvertToStringObject");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
[Test]
@@ -204,14 +212,16 @@
// if the value passed to Convert.ToString is null or
not
Assert.IsNull (Convert.ToString ((string) null),
"Convert.ToString((string)null)");
type = GetTest
("ToStringReturningConvertToStringString");
- Assert.IsNotNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
[Test]
public void ReturningTypeName ()
{
type = GetTest ("ToStringReturningTypeName");
- Assert.IsNull (rule.CheckType (type, runner));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType
(type), "RuleResult");
+ Assert.AreEqual (0, runner.Defects.Count, "Count");
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches