示例#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);
            }
        }
示例#2
0
 public static void Matches(String pattern, Exception e)
 {
     try {
         Matches(pattern, e.Message);
     } catch (Exception matchFailed) {
         Bomb.toss("incorrect exception " + e, matchFailed);
     }
 }
示例#3
0
 public static void Matches(string pattern, string message)
 {
     if (Regex.IsMatch(message, pattern))
     {
         return;
     }
     Bomb.toss(pattern + "\nnot found in\n" + message);
 }
示例#4
0
 public static void Matches(List <string> expected, List <string> actual)
 {
     try {
         Objects.each(expected, actual, Matches);
     } catch (Exception e) {
         throw Bomb.toss("Expected list equality, but actual\n" + Objects.toShortString(actual) + "\ndid not match\n" + Objects.toShortString(expected), e);
     }
 }
示例#5
0
 public static void HaveSameCount <T1, T2>(List <T1> ones, List <T2> twos)
 {
     if (ones.Count == twos.Count)
     {
         return;
     }
     throw Bomb.toss("lists have different counts - \nONES: \n" + O.toShortString(ones) + "\nTWOS:\n" + O.toShortString(twos));
 }
示例#6
0
 public static void HaveSameCount <T1, T2>(T1[] ones, T2[] twos)
 {
     if (ones.GetLength(0) == twos.GetLength(0))
     {
         return;
     }
     throw Bomb.toss("lists have different counts - \nONES: \n" + O.toShortString(ones) + "\nTWOS:\n" + O.toShortString(twos));
 }
示例#7
0
 static void failsWithNestedException()
 {
     try {
         DatesMatch("2000/07/07", "2000/07/08");
     }
     catch (Exception e) {
         Bomb.toss("caught an exception", e);
     }
 }
示例#8
0
        static void handleEachError <T>(IEnumerable <T> items, int i, T current, Exception e)
        {
            var currentStr = "tostring failed.";

            try {
                currentStr = current.ToString();
            } catch (Exception tose) {
                LogC.err("tostring on item failed", tose);
            }
            throw Bomb.toss("failed@" + i + ", processing: " + currentStr + " in " + toShortString(items), e);
        }
示例#9
0
        public static int runCommand(string command, string args)
        {
            var process = Process.Start(command, args);

            if (process == null)
            {
                throw Bomb.toss("cannot run fftwlogin.bat");
            }
            process.WaitForExit();
            return(process.ExitCode);
        }
示例#10
0
 public static void wait(int numWaits, int waitMillis, Predicate isTrue)
 {
     for (var i = 0; i < numWaits; i++)
     {
         if (isTrue())
         {
             return;
         }
         sleep(waitMillis);
     }
     Bomb.toss("condition for wait() never satisfied");
 }
示例#11
0
        public static void runProcess(string exe, string parameters)
        {
            var process = Process.Start(new ProcessStartInfo(exe, parameters)
            {
                WindowStyle = ProcessWindowStyle.Hidden
            });

            if (process == null)
            {
                throw Bomb.toss("failed to start process \n" + exe + " " + parameters);
            }
            process.WaitForExit();
            Bomb.unless(process.ExitCode == 0, () => "command returned " + process.ExitCode + ".\n" + exe + " " + parameters);
        }
示例#12
0
        public static int indexOf <T>(IEnumerable <T> ts, Predicate <T> isSelected)
        {
            var i = 0;

            foreach (var t in ts)
            {
                if (isSelected(t))
                {
                    return(i);
                }
                i++;
            }
            throw Bomb.toss("Could not find an appropriate element in " + toShortString(ts));
        }
示例#13
0
        public static void each <T1, T2>(IEnumerable <T1> ones, IEnumerable <T2> twos, Action <int, T1, T2> run)
        {
            var twosEnum = twos.GetEnumerator();

            each(
                ones,
                delegate(int i, bool last, T1 one) {
                if (!twosEnum.MoveNext())
                {
                    Bomb.toss(mismatched(ones, twos));
                }
                run(i, one, twosEnum.Current);
            });
            Bomb.when(twosEnum.MoveNext(), () => mismatched(ones, twos));
        }
示例#14
0
        public static void waitMatches <T>(T expected, Producer <T> actual)
        {
            var actual_ = default(T);

            try { O.wait(() => (actual_ = actual()).Equals(expected)); }
            catch (Exception e) {
                if (actual_.ToString().Equals(expected.ToString()))
                {
                    Bomb.toss(
                        "actual != but string matched\n" + expected + "\n" +
                        "actual Type:" + actual_.GetType().FullName + "\n" +
                        "expected type:" + expected.GetType().FullName, e);
                }
                Bomb.toss(actual_ + "\n    Did not match\n" + expected, e);
            }
        }
示例#15
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!");
        }