X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;ds=sidebyside;f=t%2Ftests.t;h=3fbdb3efa1de73bba69fdd8f43bdf24e20f5179a;hb=49540cde704094918ad460f476ef65edb1a3d4f0;hp=0641e45241a61834eca143c8a846ee832a2088ea;hpb=affd2ba7dcef980b10553894e0aa40ac1c7dd14e;p=blhc%2Fblhc.git
diff --git a/t/tests.t b/t/tests.t
index 0641e45..3fbdb3e 100644
--- a/t/tests.t
+++ b/t/tests.t
@@ -1,6 +1,6 @@
# Tests for blhc.
#
-# Copyright (C) 2012 Simon Ruderich
+# Copyright (C) 2012-2013 Simon Ruderich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
use strict;
use warnings;
-use Test::More tests => 182;
+use Test::More tests => 204;
sub is_blhc {
@@ -38,7 +38,11 @@ sub is_blhc {
$options = ' '. $options;
}
is $? >> 8, $exit, "$file$options (exit code)";
- is $output, $expected, "$file$options (output)";
+ # Perform regex or string match.
+ my $cmd = (ref $expected eq 'Regexp')
+ ? \&like
+ : \&is;
+ &$cmd($output, $expected, "$file$options (output)");
}
@@ -57,7 +61,7 @@ is_blhc '', '', 2,
$usage;
is_blhc '', '--version', 0,
- 'blhc 0.02 Copyright (C) 2012 Simon Ruderich
+ 'blhc 0.03 Copyright (C) 2012-2013 Simon Ruderich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -73,6 +77,16 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
';
+is_blhc '', '--help', 1,
+ qr/^Usage:
+ blhc \[\*options\*\] \*\.\.\*
+
+Options:
+/s;
+
+is_blhc 'doesnt-exist', '', 2,
+ qr{^No such file: \./t/logs/doesnt-exist at \./bin/blhc line \d+\.$};
+
# No compiler commands found.
@@ -114,6 +128,12 @@ is_blhc 'ignore-flag', '--ignore-arch-flag -g:', 2,
Usage:
blhc [*options*] *..*
+';
+is_blhc 'ignore-flag', '--ignore-arch-flag :amd64', 2,
+ 'Value ":amd64" invalid for option ignore-arch-flag ("arch:flag" expected)
+Usage:
+ blhc [*options*] *..*
+
';
# Wrong architecture.
@@ -171,6 +191,12 @@ is_blhc 'ignore-line', '--ignore-arch-line .+:', 2,
Usage:
blhc [*options*] *..*
+';
+is_blhc 'ignore-line', '--ignore-arch-line :amd64', 2,
+ 'Value ":amd64" invalid for option ignore-arch-line ("arch:line" expected)
+Usage:
+ blhc [*options*] *..*
+
';
# Wrong architecture.
@@ -485,10 +511,24 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp
CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-c.c
CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c ../../../../src/test/test.c -o test.so.o
CPPFLAGS missing (-D_FORTIFY_SOURCE=2): g++ -o test -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test-a.cxx test-b.o test-c.o -Wl,-z,relro
-';
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=0 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-a.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=1 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-b.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-c.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=0 -c test-d.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=0 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-e.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=1 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-f.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -U_FORTIFY_SOURCE -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-g.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -U_FORTIFY_SOURCE -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-h.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -c test-i.c
+';
+
+is_blhc 'bad-cppflags', '--ignore-flag -D_FORTIFY_SOURCE=2', 0,
+ '';
my $bad_ldflags =
'LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest
+LDFLAGS missing (-Wl,-z,relro): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o
+LDFLAGS missing (-Wl,-z,relro): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o test.h
';
is_blhc 'bad-ldflags', '', 8,
$bad_ldflags;
@@ -497,15 +537,21 @@ is_blhc 'bad-ldflags', '--pie', 8,
CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c
CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-c.c
LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest
+LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o
+LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o test.h
';
is_blhc 'bad-ldflags', '--bindnow', 8,
'LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test-b.o test-c.o -ltest
+LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o
+LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o test.h
';
is_blhc 'bad-ldflags', '--pie --bindnow', 8,
'CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c
CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c
CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-c.c
LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test-b.o test-c.o -ltest
+LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o
+LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -o test test-a.o test-b.o test-c.o test.h
';
is_blhc 'bad-multiline', '', 8,
@@ -609,6 +655,11 @@ is_blhc 'make', '', 1,
$empty;
+# qt4
+
+is_blhc 'qt4', '', 1,
+ $empty;
+
# cc
@@ -697,6 +748,22 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): g++-4.6 -Wl,-z,defs -o tes
';
+# ada
+
+my $ada = 'CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.c
+LDFLAGS missing (-Wl,-z,relro): /usr/bin/gcc-4.6 -shared -lgnat-4.6 -o libtest.so.2 test-a.o test-b.o test-c.o -Wl,--as-needed
+CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): gcc -c -g -O2 test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -g -O2 test.c
+CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): gcc -g -O2 test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 test.c
+LDFLAGS missing (-Wl,-z,relro): gcc -g -O2 test.c
+';
+is_blhc 'ada', '', 8,
+ $ada;
+is_blhc 'ada-pbuilder', '', 8,
+ $ada;
+
+
# libtool
is_blhc 'libtool', '--bindnow', 8,
@@ -721,6 +788,10 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,now): gcc -g -O2 -fstack-protector --param=ss
CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): /bin/bash ../libtool --tag=CC --mode=link gcc -Wl,-z,relro -o test.so test.c
CPPFLAGS missing (-D_FORTIFY_SOURCE=2): /bin/bash ../libtool --tag=CC --mode=link gcc -Wl,-z,relro -o test.so test.c
LDFLAGS missing (-fPIE -pie -Wl,-z,now): /bin/bash ../libtool --tag=CC --mode=link gcc -Wl,-z,relro -o test.so test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): /bin/sh ../libtool --mode=link gcc -Wl,-z,relro -o libtest.la test.h test-a.lo test-b.lo test-c.lo test-d.la
+LDFLAGS missing (-fPIE -pie -Wl,-z,now): /bin/sh ../libtool --mode=link gcc -Wl,-z,relro -o libtest.la test.h test-a.lo test-b.lo test-c.lo test-d.la
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): /bin/sh ../libtool --mode=link gcc -o libtest.la test.h test-a.lo test-b.lo test-c.lo test-d.la
+LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): /bin/sh ../libtool --mode=link gcc -o libtest.la test.h test-a.lo test-b.lo test-c.lo test-d.la
';
@@ -759,6 +830,12 @@ LDFLAGS missing (-pie -Wl,-z,relro): gcc -fPIE -o test test.o
';
+# architecture in older buildd logs
+
+is_blhc 'buildd-architecture-old', '', 0,
+ '';
+
+
# ignore architecture
is_blhc ['arch-avr32', 'arch-i386', 'empty', 'arch-mipsel'],
@@ -803,6 +880,8 @@ my $debian_hardening_wrapper =
';
is_blhc 'debian-hardening-wrapper', '', 16,
$debian_hardening_wrapper;
+is_blhc 'debian-hardening-wrapper-pbuilder', '', 16,
+ $debian_hardening_wrapper;
# false positives
@@ -813,39 +892,42 @@ is_blhc 'false-positives', '', 1,
# buildd support
-is_blhc 'empty', '--buildd', 1,
- 'I-no-compiler-commands
+is_blhc 'empty', '--buildd', 0,
+ 'I-no-compiler-commands||
';
is_blhc 'buildd-package-details', '--buildd', 0,
'';
-is_blhc 'buildd-dpkg-dev', '--buildd', 8,
- 'W-dpkg-buildflags-missing CPPFLAGS 7 (of 7), CFLAGS 6 (of 6), CXXFLAGS 1 (of 1), LDFLAGS 2 (of 2) missing
+is_blhc 'buildd-dpkg-dev', '--buildd', 0,
+ 'W-dpkg-buildflags-missing|CPPFLAGS 7 (of 7), CFLAGS 6 (of 6), CXXFLAGS 1 (of 1), LDFLAGS 2 (of 2) missing|
';
-is_blhc 'buildd-dpkg-dev-old', '--buildd', 8,
- 'W-dpkg-buildflags-missing CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing
+is_blhc 'buildd-dpkg-dev-old', '--buildd', 0,
+ 'W-dpkg-buildflags-missing|CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing|
';
-is_blhc 'buildd-dpkg-dev-missing', '--buildd', 8,
- 'W-dpkg-buildflags-missing CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing
+is_blhc 'buildd-dpkg-dev-missing', '--buildd', 0,
+ 'W-dpkg-buildflags-missing|CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing|
';
-is_blhc 'debian-hardening-wrapper', '--buildd', 16,
- 'I-hardening-wrapper-used
+is_blhc 'debian-hardening-wrapper', '--buildd', 0,
+ 'I-hardening-wrapper-used||
+';
+is_blhc 'debian-hardening-wrapper-pbuilder', '--buildd', 0,
+ 'I-hardening-wrapper-used||
';
-is_blhc 'buildd-verbose-build', '--buildd', 4,
- 'W-compiler-flags-hidden 1 (of 5) hidden
+is_blhc 'buildd-verbose-build', '--buildd', 0,
+ 'W-compiler-flags-hidden|1 (of 5) hidden|
';
-is_blhc 'make', '--buildd', 1,
- 'I-no-compiler-commands
+is_blhc 'make', '--buildd', 0,
+ 'I-no-compiler-commands||
';
-is_blhc 'debian-cmake', '--buildd', 32,
- 'I-invalid-cmake-used 2.8.7-1
+is_blhc 'debian-cmake', '--buildd', 0,
+ 'I-invalid-cmake-used|2.8.7-1|
';