Esempio n. 1
0
 public void EndAnalysisLog()
 {
     AnalysisLog.Flush();
     AnalysisLog.OutputToConsole = false;
     foreach (var d in _toDispose.MaybeEnumerate())
     {
         d.Dispose();
     }
     _toDispose = null;
 }
Esempio n. 2
0
        private static int RunPathTests()
        {
            var fg = Console.ForegroundColor;

            foreach (var ver in VERSIONS)
            {
                if (VERBOSE)
                {
                    try {
                        if (File.Exists(string.Format("AnalysisTests.Path.{0}.csv", ver.Version)))
                        {
                            File.Delete(string.Format("AnalysisTests.Path.{0}.csv", ver.Version));
                        }
                    } catch { }
                }
            }

            int failures = 0;

            foreach (var path in OTHER_ARGS)
            {
                if (!Directory.Exists(path))
                {
                    continue;
                }

                foreach (var ver in VERSIONS)
                {
                    if (VERBOSE)
                    {
                        AnalysisLog.ResetTime();
                        AnalysisLog.Output = new StreamWriter(new FileStream(string.Format("AnalysisTests.Path.{0}.csv", ver.Version), FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF8);
                        AnalysisLog.AsCSV  = true;
                        AnalysisLog.Add("Path Start", path, ver.Version, DateTime.Now);
                    }

                    if (!RunOneTest(() => { new AnalysisTest().AnalyzeDir(path, ver.Version); }, string.Format("{0}: {1}", ver.Version, path)))
                    {
                        failures += 1;
                    }
                    Console.ForegroundColor = fg;

                    if (VERBOSE)
                    {
                        AnalysisLog.Flush();
                    }

                    IdDispenser.Clear();
                }
            }
            return(failures);
        }
Esempio n. 3
0
        private static int RunDjangoTests()
        {
            var fg = Console.ForegroundColor;

            foreach (var ver in VERSIONS)
            {
                if (VERBOSE)
                {
                    try {
                        if (File.Exists(string.Format("AnalysisTests.Django.{0}.csv", ver.Version)))
                        {
                            File.Delete(string.Format("AnalysisTests.Django.{0}.csv", ver.Version));
                        }
                    } catch { }
                }
            }

            int failures = 0;

            foreach (var ver in VERSIONS)
            {
                var djangoPath = Path.Combine(ver.PrefixPath, "Lib", "site-packages", "django");
                if (!Directory.Exists(djangoPath))
                {
                    Trace.TraceInformation("Path {0} not found; skipping {1}", djangoPath, ver.Version);
                    continue;
                }

                if (VERBOSE)
                {
                    AnalysisLog.ResetTime();
                    AnalysisLog.Output = new StreamWriter(new FileStream(string.Format("AnalysisTests.Django.{0}.csv", ver.Version), FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF8);
                    AnalysisLog.AsCSV  = true;
                    AnalysisLog.Add("Django Start", ver.InterpreterPath, ver.Version, DateTime.Now);
                }

                if (!RunOneTest(() => { new AnalysisTest().AnalyzeDir(djangoPath, ver.Version); }, ver.InterpreterPath))
                {
                    failures += 1;
                }
                Console.ForegroundColor = fg;

                if (VERBOSE)
                {
                    AnalysisLog.Flush();
                }

                IdDispenser.Clear();
            }
            return(failures);
        }
Esempio n. 4
0
        private static int RunStdLibTests()
        {
            var fg = Console.ForegroundColor;

            foreach (var ver in VERSIONS)
            {
                if (VERBOSE)
                {
                    try {
                        if (File.Exists(string.Format("AnalysisTests.StdLib.{0}.csv", ver.Version)))
                        {
                            File.Delete(string.Format("AnalysisTests.StdLib.{0}.csv", ver.Version));
                        }
                    } catch { }
                }
            }

            int failures = 0;

            foreach (var ver in VERSIONS)
            {
                if (VERBOSE)
                {
                    AnalysisLog.ResetTime();
                    AnalysisLog.Output = new StreamWriter(new FileStream(string.Format("AnalysisTests.StdLib.{0}.csv", ver.Version), FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF8);
                    AnalysisLog.AsCSV  = true;
                    AnalysisLog.Add("StdLib Start", ver.InterpreterPath, ver.Version, DateTime.Now);
                }

                if (!RunOneTest(() => {
                    new AnalysisTest().AnalyzeDir(Path.Combine(ver.PrefixPath, "Lib"), ver.Version, new[] { "site-packages" });
                }, ver.InterpreterPath))
                {
                    failures += 1;
                }
                Console.ForegroundColor = fg;

                if (VERBOSE)
                {
                    AnalysisLog.Flush();
                }

                IdDispenser.Clear();
            }
            return(failures);
        }
Esempio n. 5
0
        private static bool RunOneTest(Action test, string name)
        {
            if (Debugger.IsAttached)
            {
                return(RunOneTestWithoutEH(test, name));
            }

            var sw = new Stopwatch();

            try {
                sw.Start();
                return(RunOneTestWithoutEH(test, name));
            } catch (Exception e) {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Red;
#if TRACE
                Trace.TraceError("Test failed: {0}, {1} ({2}ms)", name, sw.Elapsed, sw.ElapsedMilliseconds);
#endif
                Console.WriteLine("Test failed: {0}, {1} ({2}ms)", name, sw.Elapsed, sw.ElapsedMilliseconds);
                Console.WriteLine(e);
                AnalysisLog.Flush();
                return(false);
            }
        }
Esempio n. 6
0
        public void Analyze(Deque <AnalysisUnit> queue, CancellationToken cancel, Action <int> reportQueueSize = null, int reportQueueInterval = 1)
        {
            if (cancel.IsCancellationRequested)
            {
                return;
            }
            try {
                // Including a marker at the end of the queue allows us to see in
                // the log how frequently the queue empties.
                var endOfQueueMarker  = new AnalysisUnit(null, null);
                int queueCountAtStart = queue.Count;
                int reportInterval    = reportQueueInterval - 1;

                if (queueCountAtStart > 0)
                {
                    queue.Append(endOfQueueMarker);
                }

                while (queue.Count > 0 && !cancel.IsCancellationRequested)
                {
                    _unit = queue.PopLeft();

                    if (_unit == endOfQueueMarker)
                    {
                        AnalysisLog.EndOfQueue(queueCountAtStart, queue.Count);
                        if (reportInterval < 0 && reportQueueSize != null)
                        {
                            reportQueueSize(queue.Count);
                        }

                        queueCountAtStart = queue.Count;
                        if (queueCountAtStart > 0)
                        {
                            queue.Append(endOfQueueMarker);
                        }
                        continue;
                    }

                    AnalysisLog.Dequeue(queue, _unit);
                    if (reportInterval == 0 && reportQueueSize != null)
                    {
                        reportQueueSize(queue.Count);
                        reportInterval = reportQueueInterval - 1;
                    }
                    else if (reportInterval > 0)
                    {
                        reportInterval -= 1;
                    }

                    _unit.IsInQueue = false;
                    SetCurrentUnit(_unit);
                    AnalyzedEntries.Add(_unit.ProjectEntry);
                    _unit.Analyze(this, cancel);
                }

                if (reportQueueSize != null)
                {
                    reportQueueSize(0);
                }

                if (cancel.IsCancellationRequested)
                {
                    AnalysisLog.Cancelled(queue);
                }
            } finally {
                AnalysisLog.Flush();
                AnalyzedEntries.Remove(null);
            }
        }