Add a simple test for checkSpace.pl

This script is not expected to work on windows due to line-ending
issues, so I'm not making it get run on an automated basis.  We
should use it when editing checkSpace.pl.

Closes ticket 32613.
This commit is contained in:
Nick Mathewson 2019-11-26 13:10:39 -05:00 committed by teor
parent 2aaa7ae6e2
commit bd61a4e848
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A
7 changed files with 154 additions and 0 deletions

23
scripts/maint/checkSpaceTest.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
# Copyright 2019, The Tor Project, Inc.
# See LICENSE for licensing information
# Integration test for checkSpace.pl, which we want to rewrite.
umask 077
set -e
# make a safe space for temporary files
DATA_DIR=$(mktemp -d -t tor_checkspace_tests.XXXXXX)
trap 'rm -rf "$DATA_DIR"' 0
RECEIVED_FNAME="${DATA_DIR}/got.txt"
cd "$(dirname "$0")/checkspace_tests"
# we expect this to give an error code.
../checkSpace.pl -C ./*.[ch] ./*/*.[ch] > "${RECEIVED_FNAME}" && exit 1
diff -u expected.txt "${RECEIVED_FNAME}" || exit 1
echo "OK"

View File

@ -0,0 +1,83 @@
// The { coming up should be on its own line.
int
foo(void) {
// There should be a space before (1)
if(1) x += 1;
// The following empty line is unnecessary.
}
// There should be a newline between void and bar.
void bar(void)
{
// too wide:
testing("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
long
bad_spacing()
{
// here comes a tab
return 2;
// here comes a label without space:
foo:
;
}
// Here comes a CR:
// Trailing space:
int
non_k_and_r(void)
{
// non-k&r
if (foo)
{
// double-semi
return 1;;
}
else
{
return 2;
}
}
// #else #if causes a warning.
#if 1
#else
#if 2
#else
#endif
#endif
// always space before a brace.
foo{
}
void
unexpected_space(void)
{
// This space gives a warning.
foobar (77);
}
void
bad_function_calls(long)
{
// These are forbidden:
assert(1);
memcmp("a","b",1);
strcat(foo,x);
strcpy(foo,y);
sprintf(foo,"x");
malloc(7);
free(p);
realloc(p);
strdup(s);
strndup(s,10);
calloc(a,b);
}

View File

@ -0,0 +1,4 @@
// no guards.
int foo(int);

View File

@ -0,0 +1,31 @@
fn() {:./dubious.c:4
KW(:./dubious.c:6
UnnecNL:./dubious.c:10
DoubleNL:./dubious.c:12
tp fn():./dubious.c:15
Wide:./dubious.c:17
TAB:./dubious.c:24
nosplabel:./dubious.c:26
CR:./dubious.c:30
Space@EOL:./dubious.c:32
non-K&R {:./dubious.c:39
;;:./dubious.c:41
}\nelse:./dubious.c:43
#else#if:./dubious.c:52
o{:./dubious.c:58
fn() {:./dubious.c:58
fn ():./dubious.c:65
assert:./dubious.c:72 (use tor_assert)
memcmp:./dubious.c:73 (use {tor,fast}_mem{eq,neq,cmp}
strcat(:./dubious.c:74
strcpy(:./dubious.c:75
sprintf(:./dubious.c:76
malloc(:./dubious.c:77 (use tor_malloc, tor_free, etc)
free(:./dubious.c:78 (use tor_malloc, tor_free, etc)
realloc(:./dubious.c:79 (use tor_malloc, tor_free, etc)
strdup(:./dubious.c:80 (use tor_malloc, tor_free, etc)
strndup(:./dubious.c:81 (use tor_malloc, tor_free, etc)
calloc(:./dubious.c:82 (use tor_malloc, tor_free, etc)
noguard:./dubious.h (No #ifndef/#define header guard pair found)
dupguard:./same_guard.h (Guard macro GUARD_MACRO_H also used in ./good_guard.h)
dup fname:./subdir/dubious.c (same as ./dubious.c).

View File

@ -0,0 +1,6 @@
#ifndef GUARD_MACRO_H
#define GUARD_MACRO_H
int bar(void);
#endif

View File

@ -0,0 +1,6 @@
#ifndef GUARD_MACRO_H
#define GUARD_MACRO_H
int bar(void);
#endif

View File

@ -0,0 +1 @@
// Nothing wrong with this file, but the name is a duplicate.