Test creating module failure from garbage data in MemoryBuffer.
Also finished coverage on context.rs
extern crate inkwell;
use self::inkwell::context::Context;
+use self::inkwell::memory_buffer::MemoryBuffer;
use std::env::temp_dir;
use std::fs::{File, remove_file};
use std::io::Read;
@@ -115,3 +116,14 @@ fn test_write_and_load_memory_buffer() {
assert_eq!(module2.get_function("my_fn").unwrap().print_to_string(), function.print_to_string());
}
+
+#[test]
+fn test_garbage_ir_fails_create_module_from_ir() {
+ let context = Context::create();
+ let memory_buffer = MemoryBuffer::create_from_memory_range("garbage ir data", "my_ir");
+
+ // REVIEW: Why isn't this "garbage ir data"?
+ assert_eq!(memory_buffer.as_slice().to_str().unwrap(), "");
+ assert!(memory_buffer.get_size() > 0);
+ assert!(context.create_module_from_ir(memory_buffer).is_err());
+}
