예제 #1
0
        public void WriteToFileTest( )
        {
            string path = Path.GetTempFileName( );

            try
            {
                using (var module = new NativeModule(TestModuleName))
                {
                    Function testFunc = CreateSimpleVoidNopTestFunction(module, "foo");
                    module.WriteToFile(path);
                }

                using (var ctx = new Context( ))
                    using (var module2 = NativeModule.LoadFrom(path, ctx))
                    {
                        Function testFunc = module2.GetFunction("foo");

                        // verify basics
                        Assert.IsNotNull(testFunc);
                        string txt = module2.WriteToString( );
                        Assert.IsFalse(string.IsNullOrWhiteSpace(txt));
                        string expectedText = File.ReadAllText("TestModuleAsString.ll")
                                              .Replace("; ModuleID = 'test'", $"; ModuleID = '{path}'");
                        Assert.AreEqual(expectedText, txt);
                    }
            }
            finally
            {
                File.Delete(path);
            }
        }