aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula
diff options
context:
space:
mode:
authorAdam Vandenberg2013-03-12 21:31:34 -0700
committerAdam Vandenberg2013-03-12 21:31:34 -0700
commit684fdd3b4b88cfbb1f271710540220b4672ff357 (patch)
tree2ef3026ad3d12828b6ed554edeeb79b424b1be51 /Library/Formula
parent687062f7f57bba29d2beb05085dc1968134df7ff (diff)
downloadhomebrew-684fdd3b4b88cfbb1f271710540220b4672ff357.tar.bz2
libffi: add test
Diffstat (limited to 'Library/Formula')
-rw-r--r--Library/Formula/libffi.rb62
1 files changed, 61 insertions, 1 deletions
diff --git a/Library/Formula/libffi.rb b/Library/Formula/libffi.rb
index c82ff9304..fa8564830 100644
--- a/Library/Formula/libffi.rb
+++ b/Library/Formula/libffi.rb
@@ -12,7 +12,67 @@ class Libffi < Formula
def install
ENV.universal_binary
- system "./configure", "--prefix=#{prefix}", "--disable-debug", "--disable-dependency-tracking"
+ system "./configure", "--disable-debug", "--disable-dependency-tracking",
+ "--prefix=#{prefix}"
system "make install"
end
+
+ test do
+ (testpath/'closure.c').write <<-TEST_SCRIPT.undent
+ #include <stdio.h>
+ #include <ffi.h>
+
+ /* Acts like puts with the file given at time of enclosure. */
+ void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
+ FILE *stream)
+ {
+ *ret = fputs(*(char **)args[0], stream);
+ }
+
+ int main()
+ {
+ ffi_cif cif;
+ ffi_type *args[1];
+ ffi_closure *closure;
+
+ int (*bound_puts)(char *);
+ int rc;
+
+ /* Allocate closure and bound_puts */
+ closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
+
+ if (closure)
+ {
+ /* Initialize the argument info vectors */
+ args[0] = &ffi_type_pointer;
+
+ /* Initialize the cif */
+ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
+ &ffi_type_uint, args) == FFI_OK)
+ {
+ /* Initialize the closure, setting stream to stdout */
+ if (ffi_prep_closure_loc(closure, &cif, puts_binding,
+ stdout, bound_puts) == FFI_OK)
+ {
+ rc = bound_puts("Hello World!");
+ /* rc now holds the result of the call to fputs */
+ }
+ }
+ }
+
+ /* Deallocate both closure, and bound_puts */
+ ffi_closure_free(closure);
+
+ return 0;
+ }
+ TEST_SCRIPT
+
+ cellar = `brew --prefix libffi`.chomp
+ ENV['PKG_CONFIG_PATH'] = "#{cellar}/lib/pkgconfig/"
+ flags = *`pkg-config --cflags --libs libffi`.split
+ flags += ENV.cflags.split
+ ohai flags
+ system ENV.cc, "-o", "closure", "closure.c", *flags
+ system "./closure"
+ end
end