aboutsummaryrefslogtreecommitdiff
path: root/scripts/maint/checkspace_tests
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/maint/checkspace_tests')
-rw-r--r--scripts/maint/checkspace_tests/dubious.c83
-rw-r--r--scripts/maint/checkspace_tests/dubious.h4
-rw-r--r--scripts/maint/checkspace_tests/expected.txt31
-rw-r--r--scripts/maint/checkspace_tests/good_guard.h6
-rw-r--r--scripts/maint/checkspace_tests/same_guard.h6
-rw-r--r--scripts/maint/checkspace_tests/subdir/dubious.c1
6 files changed, 131 insertions, 0 deletions
diff --git a/scripts/maint/checkspace_tests/dubious.c b/scripts/maint/checkspace_tests/dubious.c
new file mode 100644
index 0000000000..59c5f8e4fe
--- /dev/null
+++ b/scripts/maint/checkspace_tests/dubious.c
@@ -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);
+}
diff --git a/scripts/maint/checkspace_tests/dubious.h b/scripts/maint/checkspace_tests/dubious.h
new file mode 100644
index 0000000000..744ec33955
--- /dev/null
+++ b/scripts/maint/checkspace_tests/dubious.h
@@ -0,0 +1,4 @@
+
+// no guards.
+
+int foo(int);
diff --git a/scripts/maint/checkspace_tests/expected.txt b/scripts/maint/checkspace_tests/expected.txt
new file mode 100644
index 0000000000..935b750ef9
--- /dev/null
+++ b/scripts/maint/checkspace_tests/expected.txt
@@ -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).
diff --git a/scripts/maint/checkspace_tests/good_guard.h b/scripts/maint/checkspace_tests/good_guard.h
new file mode 100644
index 0000000000..b792912d90
--- /dev/null
+++ b/scripts/maint/checkspace_tests/good_guard.h
@@ -0,0 +1,6 @@
+#ifndef GUARD_MACRO_H
+#define GUARD_MACRO_H
+
+int bar(void);
+
+#endif
diff --git a/scripts/maint/checkspace_tests/same_guard.h b/scripts/maint/checkspace_tests/same_guard.h
new file mode 100644
index 0000000000..b792912d90
--- /dev/null
+++ b/scripts/maint/checkspace_tests/same_guard.h
@@ -0,0 +1,6 @@
+#ifndef GUARD_MACRO_H
+#define GUARD_MACRO_H
+
+int bar(void);
+
+#endif
diff --git a/scripts/maint/checkspace_tests/subdir/dubious.c b/scripts/maint/checkspace_tests/subdir/dubious.c
new file mode 100644
index 0000000000..7f22bf79bf
--- /dev/null
+++ b/scripts/maint/checkspace_tests/subdir/dubious.c
@@ -0,0 +1 @@
+// Nothing wrong with this file, but the name is a duplicate.