Esempio n. 1
0
        public void TransitiveReductionGrapherTest()
        {
            var rs = new DependencyRuleSet(new CheckerContext(false));

            rs.AddGraphAbstractions("<test>", 0, "% (**)");

            var options = new Options {
                DotFilename         = Path.Combine(Path.GetTempPath(), "test.dot"),
                ShowTransitiveEdges = true
            };
            var dg   = new DependencyGrapher(new DependencyChecker(), options);
            var deps = new List <Dependency> {
                new Dependency("a1", "a1", "a2", "a2", null, 0, 0, 0, 0),
                new Dependency("a1", "a1", "a4", "a4", null, 0, 0, 0, 0),
                new Dependency("a2", "a2", "a3", "a3", null, 0, 0, 0, 0),
                new Dependency("a2", "a2", "a4", "a4", null, 0, 0, 0, 0),
                new Dependency("a3", "a3", "a4", "a4", null, 0, 0, 0, 0),
                new Dependency("b1", "b1", "b2", "b2", null, 0, 0, 0, 0),
                new Dependency("b1", "b1", "b4", "b4", null, 0, 0, 0, 0),
                new Dependency("b2", "b2", "b3", "b3", null, 0, 0, 0, 0),
                new Dependency("b2", "b2", "b4", "b4", null, 0, 0, 0, 0),
                new Dependency("b3", "b3", "b2", "b2", null, 0, 0, 0, 0),
                new Dependency("b3", "b3", "b4", "b4", null, 0, 0, 0, 0)
            };

            dg.Graph(rs, deps);

            // what to assert??
        }
Esempio n. 2
0
 public void Graph(DependencyRuleSet ruleSet, IEnumerable<Dependency> dependencies)
 {
     var graphAbstractions = new List<GraphAbstraction>();
     ruleSet.ExtractGraphAbstractions(graphAbstractions);
     var x = ruleSet.ExtractDependencyGroups();
     Graph(graphAbstractions, x, dependencies);
 }
Esempio n. 3
0
 /// <summary>
 /// Add one or more <c>DependencyRules</c>s from a single input
 /// line.
 /// public for testability.
 /// </summary>
 public void AddDependencyRules(DependencyRuleSet parent, string ruleFileName, uint lineNo, string line)
 {
     if (line.Contains(DependencyRuleSet.MAYUSE)) {
         foreach (var rule in CreateDependencyRules(parent, ruleFileName, lineNo, line, DependencyRuleSet.MAYUSE, false)) {
             Add(_allowed, rule);
         }
     } else if (line.Contains(DependencyRuleSet.MAYUSE_WITH_WARNING)) {
         foreach (var rule in CreateDependencyRules(parent, ruleFileName, lineNo, line, DependencyRuleSet.MAYUSE_WITH_WARNING, true)) {
             Add(_questionable, rule);
         }
     } else if (line.Contains(DependencyRuleSet.MUSTNOTUSE)) {
         foreach (var rule in CreateDependencyRules(parent, ruleFileName, lineNo, line, DependencyRuleSet.MUSTNOTUSE, false)) {
             Add(_forbidden, rule);
         }
     } else {
         throw new ApplicationException("Unexpected rule at " + ruleFileName + ":" + lineNo);
     }
 }
Esempio n. 4
0
        private static IEnumerable<DependencyRule> CreateDependencyRules(DependencyRuleSet parent, string ruleFileName, uint lineNo, string line, string sep, bool questionableRule)
        {
            DependencyRuleRepresentation rep = new DependencyRuleRepresentation(ruleFileName, lineNo, line, questionableRule);
            int i = line.IndexOf(sep);
            string usingPattern = parent.ExpandDefines(line.Substring(0, i).Trim());
            string usedPattern = parent.ExpandDefines(line.Substring(i + sep.Length).Trim());
            List<DependencyRule> deps = DependencyRule.CreateDependencyRules(usingPattern, usedPattern, rep);

            if (Log.IsVerboseEnabled) {
                Log.WriteInfo(String.Format("Rules used for checking {0} ({1}:{2})", line, ruleFileName, lineNo));
                foreach (DependencyRule d in deps) {
                    Log.WriteInfo("  " + d);
                }
            }
            return deps;
        }
Esempio n. 5
0
 public DependencyRuleSet Create(DirectoryInfo relativeRoot,
         string rulefilename,
         IDictionary<string, string> defines,
         IDictionary<string, DependencyRuleSet.Macro> macros)
 {
     string fullRuleFilename = Path.Combine(relativeRoot.FullName, rulefilename);
     DependencyRuleSet result;
     if (!_fullFilename2RulesetCache.TryGetValue(fullRuleFilename, out result)) {
         try {
             long start = Environment.TickCount;
             result = new DependencyRuleSet(this, fullRuleFilename, defines, macros);
             Log.WriteDebug("Completed reading " + fullRuleFilename + " in " +
                                                     (Environment.TickCount - start) + " ms");
             _fullFilename2RulesetCache.Add(fullRuleFilename, result);
         }
         catch (FileNotFoundException) {
             Log.WriteError("File " + fullRuleFilename + " not found");
             return null;
         }
     }
     return result;
 }
Esempio n. 6
0
        public void TransitiveReductionGrapherTest()
        {
            var rs = new DependencyRuleSet(new CheckerContext(false));
            rs.AddGraphAbstractions("<test>", 0, "% (**)");

            var options = new Options {
                DotFilename = Path.Combine(Path.GetTempPath(), "test.dot"),
                ShowTransitiveEdges = true
            };
            var dg = new DependencyGrapher(new DependencyChecker(), options);
            var deps = new List<Dependency> {
                                                new Dependency("a1", "a1", "a2", "a2", null, 0, 0, 0, 0),
                                                new Dependency("a1", "a1", "a4", "a4", null, 0, 0, 0, 0),
                                                new Dependency("a2", "a2", "a3", "a3", null, 0, 0, 0, 0),
                                                new Dependency("a2", "a2", "a4", "a4", null, 0, 0, 0, 0),
                                                new Dependency("a3", "a3", "a4", "a4", null, 0, 0, 0, 0),
                                                new Dependency("b1", "b1", "b2", "b2", null, 0, 0, 0, 0),
                                                new Dependency("b1", "b1", "b4", "b4", null, 0, 0, 0, 0),
                                                new Dependency("b2", "b2", "b3", "b3", null, 0, 0, 0, 0),
                                                new Dependency("b2", "b2", "b4", "b4", null, 0, 0, 0, 0),
                                                new Dependency("b3", "b3", "b2", "b2", null, 0, 0, 0, 0),
                                                new Dependency("b3", "b3", "b4", "b4", null, 0, 0, 0, 0)
                                            };

            dg.Graph(rs, deps);

            // what to assert??
        }