Exemplo n.º 1
0
        static void ExceptionTraceIsCorrect(bool reallyDie, Exception e, ICollection <string> patterns)
        {
            if (reallyDie)
            {
                Fail("expected failure did not occur");
            }
            if (O.isEmpty(patterns))
            {
                Bomb.toss("expected failure occurred, provide regex to Bombs\nEXPECTED:" + e);
            }
            var exceptions = O.list <Exception>();

            exceptions.Add(e);
            while (e != e.GetBaseException())
            {
                e = e.GetBaseException();
                exceptions.Add(e);
            }
            var messages = O.convert(exceptions, anE => anE.Message);

            try {
                Bomb.when(
                    patterns.Count > exceptions.Count,
                    () => "exception stack not deep enough for " + patterns.Count + " patterns:\n" + e
                    );
                O.each(patterns, messages, Matches);
            } catch (Exception matchFailed) {
                Bomb.toss("expected patterns:\n" + O.toShortString(patterns) +
                          "\ndid not match exception messages:\n" + O.toShortString(messages), matchFailed);
            }
        }
Exemplo n.º 2
0
        public static void setErr(string s)
        {
            if (O.isEmpty(s))
            {
                errors      = Console.Error;
                errFileName = null;
                consoleOut("now logging errors to console");
                return;
            }
            if (s.Equals(errFileName))
            {
                consoleOut("keeping already set error log file " + s);
                return;
            }
            if (!O.isEmpty(errFileName))
            {
                errors.Flush();
                errors.Close();
            }
            errFileName = s;
            var file = new FileInfo(s);

            errors = file.Exists ? file.AppendText() : file.CreateText();
            consoleOut("now logging errors to " + s);
        }
Exemplo n.º 3
0
        void populateNoClear(IEnumerable <string> rest, bool sortEntries)
        {
            if (O.isEmpty(rest))
            {
                return;
            }
            var items = sortEntries ? O.sort(rest) : rest;

            O.each(items, item => Items.Add(new ComboBoxItem {
                Content = item
            }));
        }
Exemplo n.º 4
0
        public static string testName()
        {
            var frames = new StackTrace(false).GetFrames();

            if (frames == null)
            {
                throw Bomb.toss("no frames on stack?");
            }
            foreach (var frame in frames)
            {
                var mb         = frame.GetMethod();
                var attributes = mb.GetCustomAttributes(typeof(TestAttribute), true);
                if (O.isEmpty(attributes))
                {
                    continue;
                }
                return(((TestAttribute)O.the(attributes)).Description);
            }
            throw Bomb.toss("no test attribute found on current test!");
        }
Exemplo n.º 5
0
        public static void setOut(string source, string destination, bool doMakeOld)
        {
            if (O.isEmpty(destination))
            {
                consoleOut("was logging to " + outFileName);
                outFile     = Console.Out;
                outFileName = null;
                consoleOut("now logging to console");
                Log.setFile(@"C:\logs\c#." + Process.GetCurrentProcess().Id + ".java.log");
                return;
            }
            if (destination.Equals(outFileName))
            {
                return;
            }
            if (!O.isEmpty(outFileName))
            {
                outFile.Flush();
                outFile.Close();
            }
            outFileName = destination;
            if (doMakeOld)
            {
                makeOld(destination);
            }
            var file = new FileInfo(destination);

            try { outFile = file.Exists ? file.AppendText() : file.CreateText(); }
            catch (Exception e) {
                try { tryAnotherFile(destination, source); }
                catch (Exception e2) {
                    lastDitchErrorLog(@"C:\logs\logging_failure", e);
                    lastDitchErrorLog(@"C:\logs\logging_failure", e2);
                }
                return;
            }
            setJavaLog(destination, doMakeOld);
            consoleOut(source + ": now logging to " + destination);
        }