diff options
author | Néstor Salceda <nestor@mono-cvs.ximian.com> | 2008-02-07 19:04:56 +0300 |
---|---|---|
committer | Néstor Salceda <nestor@mono-cvs.ximian.com> | 2008-02-07 19:04:56 +0300 |
commit | 357d28e03919dc760b41ad690f6e4638fedc45f6 (patch) | |
tree | 68101eaa041a5e4cbf0091e082a4b4bc0a54a681 /gendarme/rules/Gendarme.Rules.Smells/Test | |
parent | cc4a23045dd111081b2b3dbe86617268763944f5 (diff) |
2008-02-07 Nestor Salceda <nestor.salceda@gmail.com>
* AvoidLongMethodsRule.cs: The rule should be applied to static
constructors. Now we add several extra instructions for
each field for initialize, specially if the field is an array.
* Test/AvoidLongMethodsTest.cs: Added a test for the new strategy for
static constructors.
svn path=/trunk/mono-tools/; revision=95150
Diffstat (limited to 'gendarme/rules/Gendarme.Rules.Smells/Test')
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs | 98 | ||||
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog | 5 |
2 files changed, 98 insertions, 5 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs index ff9ae6b9..568d8cc6 100644 --- a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs @@ -51,10 +51,88 @@ namespace Gtk { } namespace Test.Rules.Smells { + public class LongStaticConstructorWithFields { + static readonly int foo; + static string bar; + static object baz; + + static LongStaticConstructorWithFields () { + foo = 5; + bar = "MyString"; + baz = new object (); + Console.WriteLine ("I'm writting a test, and I will fill a screen with some useless code"); + IList list = new ArrayList (); + list.Add ("Foo"); + list.Add (4); + list.Add (6); + + IEnumerator listEnumerator = list.GetEnumerator (); + while (listEnumerator.MoveNext ()) + Console.WriteLine (listEnumerator.Current); + + try { + list.Add ("Bar"); + list.Add ('a'); + } + catch (NotSupportedException exception) { + Console.WriteLine (exception.Message); + Console.WriteLine (exception); + } + + foreach (object value in list) { + Console.Write (value); + Console.Write (Environment.NewLine); + } + + int x = 0; + + for (int i = 0; i < 100; i++) + x++; + Console.WriteLine (x); + + string useless = "Useless String"; + + if (useless.Equals ("Other useless")) { + useless = String.Empty; + Console.WriteLine ("Other useless string"); + } + + useless = String.Concat (useless," 1"); + + for (int j = 0; j < useless.Length; j++) { + if (useless[j] == 'u') + Console.WriteLine ("I have detected an u char"); + else + Console.WriteLine ("I have detected an useless char"); + } + + try { + foreach (string environmentVariable in Environment.GetEnvironmentVariables ().Keys) + Console.WriteLine (environmentVariable); + } + catch (System.Security.SecurityException exception) { + Console.WriteLine (exception.Message); + Console.WriteLine (exception); + } - public class LongStaticConstructor { - static LongStaticConstructor () { - Console.WriteLine ("I'm writting a test, and I will fill a screen with some useless code"); + Console.WriteLine ("I will add more useless code !!"); + + try { + if (!(File.Exists ("foo.txt"))) { + File.Create ("foo.txt"); + File.Delete ("foo.txt"); + } + } + catch (IOException exception) { + Console.WriteLine (exception.Message); + Console.WriteLine (exception); + } + } + } + + public class LongStaticConstructorWithoutFields { + static LongStaticConstructorWithoutFields () { + Console.WriteLine ("I'm writting a test, and I will fill a screen with some useless code"); IList list = new ArrayList (); list.Add ("Foo"); list.Add (4); @@ -1077,9 +1155,19 @@ namespace Test.Rules.Smells { } [Test] - public void LongStaticConstructorTest () + public void LongStaticConstructorWithoutFieldsTest () + { + MethodDefinition staticConstructor = assembly.MainModule.Types["Test.Rules.Smells.LongStaticConstructorWithoutFields"].Constructors.GetConstructor (true,Type.EmptyTypes); + messageCollection = rule.CheckMethod (staticConstructor, new MinimalRunner ()); + Assert.IsNotNull (messageCollection); + Assert.AreEqual (1, messageCollection.Count); + } + + + [Test] + public void LongStaticConstructorWithFieldsTest () { - MethodDefinition staticConstructor = assembly.MainModule.Types["Test.Rules.Smells.LongStaticConstructor"].Constructors.GetConstructor (true,Type.EmptyTypes); + MethodDefinition staticConstructor = assembly.MainModule.Types["Test.Rules.Smells.LongStaticConstructorWithFields"].Constructors.GetConstructor (true,Type.EmptyTypes); messageCollection = rule.CheckMethod (staticConstructor, new MinimalRunner ()); Assert.IsNull (messageCollection); } diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog index 4ed885e8..ff2f03c1 100644 --- a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog @@ -1,3 +1,8 @@ +2008-02-07 Nestor Salceda <nestor.salceda@gmail.com> + + * AvoidLongMethodsTest.cs: Added a test for the new strategy for static + constructors. + 2008-02-06 Nestor Salceda <nestor.salceda@gmail.com> * AvoidLongMethodsTest.cs: Added a test for static constructors. This |