Exemple #1
0
        public void TestDipWithProxies()
        {
            var          gc    = new GlobalContext();
            WorkingGraph graph = gc.CurrentGraph;

            using (var f = DisposingFile.CreateTempFileWithTail(".dip")) {
                using (TextWriter tw = new StreamWriter(f.FileName)) {
                    tw.Write(@"$ NKK(Name:Key1:Key2)
                        NKK:a:keyA1:?     => ;1;0;0;src.abc|1            => NKK:?:keyA1:?
                        NKK:?:keyA1:?     => ;2;1;0;src.abc|3;example123 => NKK:a:keyA2:?
                        NKK:a:keyA2:?     => ;3;0;0;src.abc|5            => NKK:a:keyA1:KEYa1
                        NKK:?:?:KEYa2     => ;4;0;0;src.abc|7            => NKK:a:keyA2:KEYa2
                        NKK:?:keyA2:KEYa2 => ;5;1;0;src.abc|9            => NKK:b::KEYb
                        NKK:?:?:KEYb      => ;6;0;0;src.abc|11           => NKK:?:?:KEYa1
                        NKK:?::KEYb       => ;7;0;0;src.abc|13           => NKK:?:keyA2:?");
                }

                var dipReaderFactory = new DipReaderFactory();
                IEnumerable <Dependency> dependencies =
                    dipReaderFactory.CreateReader(f.FileName, false, dipReaderFactory.CreateReadingContext())
                    .ReadDependencies(gc.CurrentGraph, 0, ignoreCase: false);
                Assert.IsNotNull(dependencies);
                Item[] items = dependencies.SelectMany(d => new[] { d.UsingItem, d.UsedItem }).Distinct().ToArray();
                Assert.AreEqual(3, items.Length);
                Assert.IsTrue(items.Contains(graph.CreateItem(ItemType.Find("NKK"), "a", "keyA1", "KEYa1")));
                Assert.IsTrue(items.Contains(graph.CreateItem(ItemType.Find("NKK"), "a", "keyA2", "KEYa2")));
                Assert.IsTrue(items.Contains(graph.CreateItem(ItemType.Find("NKK"), "b", "", "KEYb")));
            }
        }
Exemple #2
0
        public void ExitException()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"$ DOTNETITEM ---> DOTNETITEM

                    // Bad - contains --->
                    =---> :=    
                       : ---> blabla
                    =:

                    // Bad - contains --->
                    --->> :=    
                       ** ---> blabla
                    =:
                ");
                }
                Assert.AreEqual(Program.EXCEPTION_RESULT, Program.Main(CreateCheckDepsArgs(d)));
            }
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"$ DOTNETITEM ---> DOTNETITEM

                    --> :=    
                       ** ---> blabla
                    =:
                ");
                }
                Assert.AreEqual(Program.EXCEPTION_RESULT, Program.Main(CreateCheckDepsArgs(d)));
            }
        }
Exemple #3
0
        public void ExitOkAspects()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"
                    $ DOTNETITEM ---> DOTNETITEM
                  
                    ::* ---> ::mscorlib

                    ** ---> **

                    // Schlägt fehlt, weil eine SpecialMethod auch auf YetAnotherMethod zugreift!
                    **::*SpecialMethod* ---> : {
                        ---> System:*
                        ---> **::*SpecialMethod*
                        ---> **::*ExtraordinaryMethod*
                    }

                    $ DOTNETASSEMBLY ---> DOTNETASSEMBLY
                    * ---> *
                    ");
                }
                Assert.AreEqual(Program.OK_RESULT, Program.Main(CreateCheckDepsArgs(d)));
            }
        }
Exemple #4
0
        public void NestedMacroTest1()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"
                    $ DOTNETITEM ---> DOTNETITEM

                    ** ---> :ExcludeFromCodeCoverageAttribute
                  
                    _B.** ---> _B.**
                    _B.** ---> System.**
                    _B.dir1.dir2:SomeClass ---? -:NamespacelessTestClassForArchichect::I
                    -:* ---? System:*

                    // Each type may declare constructors
                    DOTNETTYPE:** -- '_declaresmethod -> '_ctor

                    $ DOTNETASSEMBLY ---> DOTNETASSEMBLY
                    * ---> *");
                }
                Assert.AreEqual(Program.OK_RESULT,
                                Program.Main(
                                    new[] {
                    Program.DoDefineOption.Opt, "_A", "Archichect.TestAssembly", Program.DoDefineOption.Opt,
                    "_B", "_A"
                }.Concat(CreateCheckDepsArgs(d)).ToArray()));
            }
        }
Exemple #5
0
        public void TestIncludeExclude()
        {
            using (var f = DisposingFile.CreateTempFileWithTail("Mark.dip")) {
                Assert.AreEqual(0,
                                Program.Main(new[] {
                    Program.DoResetOption.Opt,
                    Program.TransformTestDataOption.Opt, ".", typeof(MarkDeps).Name, "{",
                    MarkDeps.DependencyMatchOptions.DependencyMatchOption.Opt, "'M--",
                    MarkDeps.DependencyMatchOptions.NoMatchOption.Opt, "->B",

                    MarkDeps.MarkLeftItemOption.Opt, "LeftMatch",
                    MarkDeps.MarkRightItemOption.Opt, "RightMatch",
                    MarkDeps.MarkDependencyItemOption.Opt, "DepMatch",
                    "}",

                    Program.WriteDipOption.Opt, f.FileName
                }));

                using (var sw = new StreamReader(f.FileName)) {
                    string o = sw.ReadToEnd();

                    Assert.IsTrue(Regex.IsMatch(o, "SIMPLE:A[^:=]*RightMatch"));
                    Assert.IsFalse(Regex.IsMatch(o, "SIMPLE:B[^:=]*RightMatch"));
                    Assert.IsTrue(Regex.IsMatch(o, "SIMPLE:C[^:=]*RightMatch"));

                    Assert.IsTrue(Regex.IsMatch(o, "SIMPLE:A[^:=]*LeftMatch"));
                    Assert.IsTrue(Regex.IsMatch(o, "SIMPLE:B[^:=]*LeftMatch"));
                    Assert.IsFalse(Regex.IsMatch(o, "SIMPLE:C[^:=]*LeftMatch"));
                }
            }
        }
Exemple #6
0
        public void ExitOk()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"
                    $ DOTNETITEM ---> DOTNETITEM

                    ** ---> :ExcludeFromCodeCoverageAttribute

                    Archichect.TestAssembly.** ---> Archichect.TestAssembly.**
                    Archichect.TestAssembly.**::Archichect.TestAssembly ---> System.**::mscorlib
                    Archichect.TestAssembly.dir1.dir2:SomeClass ---? -:NamespacelessTestClassForArchichect::I
                    -:* ---? System:*
                    Archichect.TestAssembly.** ---> Archichect.TestAssembly.**

                    // Each type may declare constructors
                    DOTNETTYPE:** -- '_declaresmethod -> '_ctor

                    $ DOTNETASSEMBLY ---> DOTNETASSEMBLY
                    * ---> *
                ");
                }
                Assert.AreEqual(Program.OK_RESULT, Program.Main(CreateCheckDepsArgs(d)));
            }
        }
Exemple #7
0
        public void TestMarkFromTo()
        {
            using (var f = DisposingFile.CreateTempFileWithTail("Mark.dip")) {
                Assert.AreEqual(0,
                                Program.Main(new[] {
                    Program.DoResetOption.Opt,
                    Program.TransformTestDataOption.Opt, ".", typeof(MarkDeps).Name, "{",
                    MarkDeps.DependencyMatchOptions.DependencyMatchOption.Opt, "'M--->'N",
                    MarkDeps.DependencyMatchOptions.DependencyMatchOption.Opt, "A--->A",

                    MarkDeps.MarkLeftItemOption.Opt, "LeftMatch",
                    MarkDeps.MarkRightItemOption.Opt, "RightMatch",
                    MarkDeps.MarkDependencyItemOption.Opt, "DepMatch",

                    MarkDeps.UnmarkLeftItemOption.Opt, "N",         // does nothing
                    MarkDeps.UnmarkRightItemOption.Opt, "M",        // removes M from A because of match of 2nd pattern
                    "}",

                    Program.WriteDipOption.Opt, f.FileName
                }));

                using (var sw = new StreamReader(f.FileName)) {
                    string o = sw.ReadToEnd();

                    Assert.IsTrue(o.Contains("SIMPLE:A'LeftMatch+RightMatch "));
                    Assert.IsTrue(o.Contains("SIMPLE:B'M "));
                    Assert.IsTrue(o.Contains("SIMPLE:C'N+RightMatch"));
                    Assert.IsTrue(o.Contains("=> 'DepMatch"));
                }
            }
        }
Exemple #8
0
        public void TestCollectArgsFromFile()
        {
            using (var f = DisposingFile.CreateTempFileWithTail(".nd")) {
                using (var sw = new StreamWriter(f.FileName)) {
                    sw.WriteLine(@"
a b                        // 1 2
c d { e1 e2                // 3 4 5 6 7 // line starting { is split!
    f1 f2 f3               // 8
    g {                    // 9
      h1 h2                // 10
      i1 i2 i3             // 11
    }                      // 12
    j { k1 k2 } l m n o {  // 13
      p } } q              // 14
r s");                     // 15 16
                }
                string[] result = Option.CollectArgsFromFile(f.FileName);
                Assert.AreEqual(16, result.Length);
                Assert.IsTrue(result.Contains("e1"));
                Assert.IsTrue(result.Contains("    f1 f2 f3               // 8"));
                Assert.IsTrue(result.Contains("      i1 i2 i3             // 11"));
                Assert.IsTrue(result.Contains("      p } } q              // 14"));
                Assert.IsTrue(result.Contains("r"));
                Assert.IsTrue(result.Contains("s"));
            }
        }
Exemple #9
0
 public void ExitNoRuleGroupsFoundForEmptyDepFile()
 {
     using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
         using (TextWriter tw = new StreamWriter(d.FileName)) {
             tw.Write("");
         }
         Assert.AreEqual(Program.NO_RULE_GROUPS_FOUND, Program.Main(CreateCheckDepsArgs(d)));
     }
 }
Exemple #10
0
 public void TestWriteTestDataOption()
 {
     using (var d = DisposingFile.CreateTempFileWithTail(".gif")) {
         // The usage typeof(...).FullName forces copying of assembly to bin directory.
         Assert.AreEqual(0,
                         Program.Main(new[] {
             TestAssemblyPath, Program.WriteTestDataOption.Opt, "Archichect.TestRenderer.dll",
             typeof(TestRendererForLoadFromAssembly).Name, d.FileName
         }));
     }
 }
Exemple #11
0
 public void TestWriteTestDataOptionWithModulesAndInterfacesRenderer()
 {
     using (var d = DisposingFile.CreateTempFileWithTail(".gif")) {
         Assert.AreEqual(0,
                         Program.Main(new[] {
             TestAssemblyPath, Program.WriteTestDataOption.Opt, ".",
             typeof(ModulesAndInterfacesRenderer).Name,
             $"{{ {GraphicsRenderer.WidthOption} 1500 {GraphicsRenderer.HeightOption} 1000 {GraphicsRenderer.TitleOption} TestGOption {ModulesAndInterfacesRenderer.InterfaceSelectorOption} MI }}",
             d.FileName
         }));
     }
 }
Exemple #12
0
        public void WriteAndReadDotNetDependencies()
        {
            using (DisposingFile dipFile = DisposingFile.CreateTempFileWithTail(".dip")) {
                int result =
                    Program.Main(new[] {
                    MainTests.TestAssemblyPath, Program.WriteDipOption.Opt, dipFile.FileName,
                    Program.DoResetOption.Opt, dipFile.FileName, Program.CountDependenciesOption.Opt
                });
                Assert.AreEqual(Program.OK_RESULT, result);

                Console.WriteLine(dipFile.FileName);
            }
        }
Exemple #13
0
        public void ExitFileNotFound()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"$ DOTNETITEM ---> DOTNETITEM

                    : ---> blabla
                ");
                }
                Assert.AreEqual(Program.FILE_NOT_FOUND_RESULT,
                                Program.Main(CreateCheckDepsArgs(d).Concat(new[] { "nonexistingfile.dll" }).ToArray()));
            }
        }
Exemple #14
0
        public void ExitDependenciesNotOk()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                // The rules are not enough for the test assembly - we expect return result 3
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"
                   $ DOTNETITEM ---> DOTNETITEM
                  
                   ** ---> blabla
                ");
                }

                Assert.AreEqual(Program.DEPENDENCIES_NOT_OK, Program.Main(CreateCheckDepsArgs(d)));
            }
        }
Exemple #15
0
        public void ExitDependenciesNotOkAspects()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"$ DOTNETITEM ---> DOTNETITEM

                    Archichect.TestAssembly.** ---> Archichect.TestAssembly.**
                    Archichect.TestAssembly.** ---> System.**
                    Archichect.TestAssembly.dir1.dir2:SomeClass ---? -:NamespacelessTestClassForArchichect::I
                    -:* ---? System:*

                    // Schlägt fehlt, weil eine SpecialMethod auch auf ExtraordinaryMethod zugreift!
                    :::*SpecialMethod* ---> : {
                       : ---> System:*
                         ---> :::*SpecialMethod*
                    }
                    ");
                }

                Assert.AreEqual(Program.DEPENDENCIES_NOT_OK,
                                Program.Main(new[] { Program.LogChattyOption.Opt }.Concat(CreateCheckDepsArgs(d)).ToArray()));
            }
        }
        public void TestAddImplementsDependencies()
        {
            using (var dipFile = DisposingFile.CreateTempFileWithTail(".dip").Keep) {
                int result = Program.Main(new[] {
                    MainTests.TestAssemblyPath,
                    Program.TransformOption.Opt, typeof(PathMarker).Name, "{",
                    PathMarker.DefineItemMatchOption.Opt, "C", "'_class",
                    PathMarker.DefineItemMatchOption.Opt, "I", "'_interface",
                    PathMarker.DefineDependencyMatchOption.Opt, "i", "'_directlyimplements",
                    PathMarker.DefineDependencyMatchOption.Opt, "d", "'_directlyderivedfrom",
                    PathMarker.RegexOption.Opt, "C#([id]:)*[id]I",
                    PathMarker.AddDependencyOption.Opt,
                    PathMarker.AddMarkerOption.Opt, "implements",
                    //PathMarker.AddIndexedMarkerOption.Opt, "implements",
                    "}",
                    Program.WriteDipOption.Opt, dipFile.FileName,
                    //typeof(FlatPathWriter).Name, "{",
                    //    FlatPathWriter.PathMarkerOption.Opt, "_directlyimplements*",
                    //    FlatPathWriter.ShowItemMarkersOption.Opt,
                    //"}", dipFile.FileName,
                });
                Assert.AreEqual(Program.OK_RESULT, result);

                using (var tr = new StreamReader(dipFile.FileName)) {
                    string o = tr.ReadToEnd().Trim();
                    Console.WriteLine(o);

                    AssertImplements(o, "AbstractImplementingClass", "ISomeBaseInterface");
                    AssertImplements(o, "ImplementingClass1", "ISomeBaseInterface");
                    AssertImplements(o, "ImplementingClass2", "ISomeBaseInterface");
                    AssertImplements(o, "AbstractImplementingClass", "ISomeInterface");
                    AssertImplements(o, "ImplementingClass1", "ISomeInterface");
                    AssertImplements(o, "ImplementingClass2", "ISomeInterface");
                    AssertImplements(o, "ISomeInterface", "ISomeBaseInterface", false);
                }
            }
        }
Exemple #17
0
        public void TestBackProjectSmallCycle()
        {
            ItemType generic2 = ItemType.Generic(2, ignoreCase: false);
            var gc = new GlobalContext();
            WorkingGraph graph = gc.CurrentGraph;

            Item a1 = graph.CreateItem(generic2, "a:1");
            Item b1 = graph.CreateItem(generic2, "b:1");
            Item a2 = graph.CreateItem(generic2, "a:2");
            Item b2 = graph.CreateItem(generic2, "b:2");
            Item b3 = graph.CreateItem(generic2, "b:3");

            var deps = new[] {
                Dep(graph, a1, b1), Dep(graph, b1, a2), Dep(graph, b2, a2), Dep(graph, a1, b3)
            };

            List<Dependency> backProjectedDeps = ProjectMarkCyclesAndBackProject(deps, gc);

            Assert.IsTrue(Find(backProjectedDeps, a1, b1).MarkersContain("C0"));
            Assert.IsTrue(Find(backProjectedDeps, a1, b3).MarkersContain("C0"));
            Assert.IsTrue(Find(backProjectedDeps, b1, a2).MarkersContain("C0"));
            Assert.IsTrue(Find(backProjectedDeps, b2, a2).MarkersContain("C0"));

            var pw = new FlatPathWriter();
            using (var t = DisposingFile.CreateTempFileWithTail(".txt")) {
                pw.Render(gc, backProjectedDeps, $"{{ {FlatPathWriter.PathMarkerOption} C* }}".Replace(" ", Environment.NewLine),
                          new WriteTarget(t.FileName, append: false, limitLinesForConsole: 100), ignoreCase: false);

                using (var sr = new StreamReader(t.FileName)) {
                    var o = sr.ReadToEnd();

                    //Console.WriteLine(o);
                    Assert.IsTrue(o.Contains("a:1"));
                    Assert.IsTrue(o.Contains("<= a:2 $"));
                }
            }
        }
Exemple #18
0
        public void TestWritePluginption()
        {
            using (var d = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(d.FileName)) {
                    tw.Write(@"
                    $ DOTNETITEM ---> DOTNETITEM
                  
                    Archichect.TestAssembly.** ---> Archichect.TestAssembly.**
                    Archichect.TestAssembly.**::Archichect.TestAssembly ---> System.**::mscorlib
                    Archichect.TestAssembly.dir1.dir2:SomeClass        ---? -:NamespacelessTestClassForArchichect::I
                    -:*                       ---? System:**
                    Archichect.TestAssembly.** ---> Archichect.TestAssembly.**

                    $ DOTNETASSEMBLY ---> DOTNETASSEMBLY
                    **          ---> **

                    $ DOTNETITEM      ---> SIMPLE(Name)
                    ! System**:**     ---> .Net
                    ! Microsoft**:**  ---> .Net
                    ! (**):(**)       ---> \1#\2
                ");
                }

                using (var e = DisposingFile.CreateTempFileWithTail(".gif")) {
                    // typeof(FullName) forces copying to known directory ...
                    Assert.AreEqual(0,
                                    Program.Main(
                                        CreateCheckDepsArgs(d)
                                        .Concat(new[] {
                        Program.WritePluginOption.Opt, "Archichect.TestRenderer.dll",
                        typeof(TestRendererForLoadFromAssembly).FullName, e.FileName
                    })
                                        .ToArray()));
                }
            }
        }
Exemple #19
0
        public void GeneralSucceedingTest()
        {
            using (var ruleFile = DisposingFile.CreateTempFileWithTail(".dll.dep")) {
                using (TextWriter tw = new StreamWriter(ruleFile.FileName, false, Encoding.Default)) {
                    tw.Write(@"
// Test dependencies for Archichect

$ DOTNETITEM ---> DOTNETITEM
                  
    // Every class may use all classes from its own namespace.
(**): ---> \1:

    // Special dependency for classes from global namespace
    // A class from the global namespace may use
    // all classes from that namespace.
-:** ---> -:**

    // Every class may use all classes from child namespaces
    // of its own namespace.
(**): ---> \1.**:

    // Every class may use all of System.
** ---> System.**:


    // Archichect may use antlr and itself.
Archichect ---> antlr

    // Archichect must not use Windows Forms.
Archichect.** ---! System.Windows.Forms.**

_TES  := asdasdasdasdasdasd
_TESTS := Archichect.TestAssembly
_TEST_OTHERS := xxxxxxxxxxxxx
_TEST := asdasdasdasdasdasd

    // Test declarations from dir1.dir2 may use declarations from dir1.dir3.
_TESTS.dir1.dir2:* ---> _TESTS.dir1.dir3:*


_TESTS.dir1:* ---> _TESTS.dir1.dir3:*
    
    // ...SomeClass.AnotherMethod may use -:NamespacelessTestClassForArchichect -
    // but this is questionable.
_TESTS.dir1.dir2:SomeClass::AnotherMethod ---? -:NamespacelessTestClassForArchichect

    // A questionable rule that never fires - it should be output.
asdlkfj.* ---? askdjf.*;

    // Umlautmatching rules
_TESTS.dirümläut.** ---> _TESTS.dirümläutö.** 
_TESTS.dirümläut.** ---> _TESTS.dirümläutß.** 
_TESTS.dirumlaut.** ---> _TESTS.dirumlauts.** 

    // Test case for ""open item 5""
    // Methods called InnerClassMethod may call each other
:::InnerClassMethod ---> :::InnerClassMethod 

    // Tests must be able to see tested classes
_TESTS.** ---> Archichect.**

    // Tests may use Microsoft.VisualStudio.TestTools.
_TESTS.** ---> Microsoft.VisualStudio.TestTools.**

// ------------------

    // In these tests, we ignore everything in the
    // current test class.
Archichect:Tests ---> **

//////// ------------------

//////    // All of system is ignored
//////% ()System.**

//////    // Classes in Archichect.Tests are shown separately, without the namespace
//////% Archichect.Tests.(**)

//////    // Classes in Archichect are also shown separately, but with the namespace
//////% (Archichect)

//////    // antlr classes are shown by namespace
//////% (antlr)
//////% (antlr.**)

//////    // Top level classes are shown as their class name
//////% -:(*)
                ");
                }

                string outFile = Path.GetTempFileName();
                int    result;
                //string workingDir = Path.GetTempPath();
                using (TextWriter tw = new StreamWriter(outFile)) {
                    TextWriter oldOut = Console.Out;
                    Console.SetOut(tw);
                    string[] args =
                    {
                        Program.LogVerboseOption.Opt,
                        Program.ConfigureOption.Opt,
                        typeof(CheckDeps).Name,             "<.",
                        CheckDeps.DefaultRuleFileOption.Opt,ruleFile.FileName,
                        ".>",
                        Program.ReadOption.Opt,
                        TestAssemblyPath
                    };
                    result = Program.Main(args);
                    Console.SetOut(oldOut);
                }
                AssertNotContains(outFile, "****");
                File.Delete(outFile);
                Assert.AreEqual(Program.OK_RESULT, result);
            }
        }