Skip to content

Commit

Permalink
libsigsegv: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
DomT4 committed Jul 19, 2015
1 parent 3eae204 commit 40b887b
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions Formula/libsigsegv.rb
@@ -1,11 +1,9 @@
require 'formula'

class Libsigsegv < Formula
desc "Library for handling page faults in user mode"
homepage 'https://www.gnu.org/software/libsigsegv/'
url 'http://ftpmirror.gnu.org/libsigsegv/libsigsegv-2.10.tar.gz'
mirror 'http://ftp.gnu.org/gnu/libsigsegv/libsigsegv-2.10.tar.gz'
sha256 '8460a4a3dd4954c3d96d7a4f5dd5bc4d9b76f5754196aa245287553b26d2199a'
homepage "https://www.gnu.org/software/libsigsegv/"
url "http://ftpmirror.gnu.org/libsigsegv/libsigsegv-2.10.tar.gz"
mirror "https://ftp.gnu.org/gnu/libsigsegv/libsigsegv-2.10.tar.gz"
sha256 "8460a4a3dd4954c3d96d7a4f5dd5bc4d9b76f5754196aa245287553b26d2199a"

bottle do
cellar :any
Expand All @@ -24,7 +22,52 @@ def install
"--prefix=#{prefix}",
"--enable-shared"
system "make"
system "make check"
system "make install"
system "make", "check"
system "make", "install"
end

test do
# Sourced from tests/efault1.c in tarball.
(testpath/"test.c").write <<-EOS.undent
#include "sigsegv.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const char *null_pointer = NULL;
static int
handler (void *fault_address, int serious)
{
abort ();
}
int
main ()
{
if (open (null_pointer, O_RDONLY) != -1 || errno != EFAULT)
{
fprintf (stderr, "EFAULT not detected alone");
exit (1);
}
if (sigsegv_install_handler (&handler) < 0)
exit (2);
if (open (null_pointer, O_RDONLY) != -1 || errno != EFAULT)
{
fprintf (stderr, "EFAULT not detected with handler");
exit (1);
}
printf ("Test passed");
return 0;
}
EOS

system ENV.cc, "test.c", "-lsigsegv", "-o", "test"
assert_match /Test passed/, shell_output("./test")
end
end

0 comments on commit 40b887b

Please sign in to comment.