Beispiel #1
0
        public void ExtendedConstructor_FileNotFoundException_Not()
        {
            const string msg  = "Test MSG";
            const string path = "Test PATH";

            try
            {
                Raise <FileNotFoundException> .IfNot(true, msg, path);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            try
            {
                Raise <FileNotFoundException> .IfNot(false, msg, path);
            }
            catch (FileNotFoundException fex)
            {
                Assert.That(fex.Message, Is.EqualTo(msg));
                Assert.That(fex.FileName, Is.EqualTo(path));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Beispiel #2
0
        public void ExtendedConstructor_BigCtorException_Not()
        {
            var x = 3;
            var y = decimal.MinValue;
            var z = "ZZZ";
            var t = new KeyValuePair <string, string>(z, z + z);

            try
            {
                Raise <BigCtorException> .IfNot(true, x, y, z, t);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            try
            {
                Raise <BigCtorException> .IfNot(false, x, y, z, t);
            }
            catch (BigCtorException fex)
            {
                Assert.That(fex.Message, Is.EqualTo(x.ToString()));
                Assert.That(fex.X, Is.EqualTo(x));
                Assert.That(fex.Y, Is.EqualTo(y));
                Assert.That(fex.Z, Is.EqualTo(z));
                Assert.That(fex.T, Is.EqualTo(t));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        private static T GetLegacyAttribute <T>(MemberInfo attributeProvider) where T : Attribute
        {
            var dllImportAttributes = attributeProvider.GetCustomAttributes(typeof(T), false)
                                      .Cast <T>()
                                      .ToArray();

            Raise <LegacyWrapperException> .IfNot(dllImportAttributes.Length == 1, $"{attributeProvider.Name} must contain exactly one {typeof(T).Name}");

            return(dllImportAttributes[0]);
        }
Beispiel #4
0
 public void ExceptionPrivateConstructor3_Not()
 {
     try
     {
         Raise <PrivateCtorException> .IfNot(false, "msg");
     }
     catch (ThrowerException)
     {
         Should.Throw <ThrowerException>(() => Raise <PrivateCtorException> .IfNot(false, "msg"));
     }
 }
 public FileNotFoundException RaiseGeneric()
 {
     try
     {
         Raise<FileNotFoundException>.IfNot(File.Exists(NotExistingFilePath), NotExistingFilePath, NotExistingFilePath);
     }
     catch (FileNotFoundException ex)
     {
         return ex;
     }
     return default(FileNotFoundException);
 }
Beispiel #6
0
        public void InvalidOperationException_WithMsg_Not()
        {
            try
            {
                Raise <InvalidOperationException> .IfNot(false, "Pino");

                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("Pino", ex.Message);
                Assert.Pass();
            }
        }
Beispiel #7
0
        public void ExceptionInternalConstructor3_Not()
        {
            try
            {
                Raise <ThrowerException> .IfNot(false, "A RANDOM MSG");

                Assert.Fail();
            }
            catch (ThrowerException ex)
            {
                Assert.AreNotEqual("A RANDOM MSG", ex.Message);
                Assert.Pass();
            }
        }
Beispiel #8
0
        public void ArgumentNullException_WithMsg_Not()
        {
            try
            {
                Raise <ArgumentNullException> .IfNot(false, "Pino");

                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("Pino", ex.Message);
                Assert.Pass();
            }
        }
Beispiel #9
0
        public static void TypeCheck(string input)
        {
            FunctionDecl main;

            using (var file = new FileStream(input, FileMode.Open)) {
                var scanner = new Scanner(file);
                var parser  = new Parser(scanner);
                Raise <ParseException> .IfNot(parser.Parse());

                main = parser.Prog;
            }
            main.Accept(new TypecheckVisitor());
            main.Accept(new ReturnCheckVisitor());
        }
Beispiel #10
0
 public void ExtendedConstructor_TooManyArgs_Not()
 {
     try
     {
         Raise <ArgumentException> .IfNot(false, 1, "SNAFU", 3.14M);
     }
     catch (ArgumentException aex)
     {
         Assert.Pass(aex.Message);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
Beispiel #11
0
 private static void ThreadTest()
 {
     for (var i = 0; i < 10000; ++i)
     {
         var msg = i.ToString(CultureInfo.InvariantCulture);
         try
         {
             Raise <ArgumentException> .IfNot(false, msg);
         }
         catch (ArgumentException ex)
         {
             Assert.AreEqual(msg, ex.Message);
         }
     }
 }
Beispiel #12
0
 public void TrueCond()
 {
     Raise <Exception> .IfNot(true);
 }
Beispiel #13
0
 public void ArgumentNullException_Not()
 {
     Should.Throw <ArgumentNullException>(() => Raise <ArgumentNullException> .IfNot(false));
 }
Beispiel #14
0
 public void ExceptionPrivateConstructor1_Not()
 {
     Should.Throw <ThrowerException>(() => Raise <PrivateCtorException> .IfNot(false));
 }
Beispiel #15
0
 public void ExceptionInternalConstructor2_Not()
 {
     Should.Throw <InternalCtorException>(() => Raise <InternalCtorException> .IfNot(false, "msg"));
 }
Beispiel #16
0
 public void ExceptionWithoutConstructor2_Not()
 {
     Should.Throw <ThrowerException>(() => Raise <NoCtorException> .IfNot(false, "msg"));
 }
Beispiel #17
0
 public void InvalidOperationException_Not()
 {
     Should.Throw <InvalidOperationException>(() => Raise <InvalidOperationException> .IfNot(false));
 }
        public void Visit(LoadStmt load)
        {
            const string   module         = "<Module>";
            const string   program        = "Program";
            const string   sysFuncs       = "SystemFunctions";
            const string   userFuncs      = "UserFunctions";
            var            foundProgram   = false;
            var            foundSysFuncs  = false;
            var            foundUserFuncs = false;
            TypeDefinition userFuncsType  = null;

            // We load the assembly given by the statement.
            Raise <TypeCheckException> .IfNot(File.Exists(load.Assembly));

            var asmDef = AssemblyDefinition.ReadAssembly(load.Assembly);
            var modDef = asmDef.MainModule;

            // Type loading; in the first pass, we load all types. After that,
            // all field types are loaded: we have to do at least two passes
            // since field types may rely on types declared in the assembly we have to load.
            var loadedTypes = new LinkedList <TypeDefinition>();

            foreach (var typeDef in modDef.Types)
            {
                switch (typeDef.Name)
                {
                case module:
                    continue;

                case program:
                    foundProgram = true;
                    continue;

                case sysFuncs:
                    foundSysFuncs = true;
                    continue;

                case userFuncs:
                    foundUserFuncs = true;
                    userFuncsType  = typeDef;
                    continue;

                default:
                    LoadType(typeDef);
                    loadedTypes.AddLast(typeDef);
                    break;
                }
            }
            // An assembly produced by this language must have
            // a set of predefined types.
            Raise <TypeCheckException> .IfNot(foundProgram && foundSysFuncs && foundUserFuncs, "Invalid assembly");

            foreach (var typeDef in loadedTypes)
            {
                LoadTypeFields(typeDef);
            }

            // Function loading...
            Debug.Assert(userFuncsType != null);
            foreach (var funcDef in userFuncsType.Methods)
            {
                LoadFunc(funcDef);
            }
        }
Beispiel #19
0
 public void AbstractException2_Not()
 {
     Should.Throw <ThrowerException>(() => Raise <AbstractException> .IfNot(false, "msg"));
 }