commit b1a12b45db9482873cf93df6539e47f1beb0e9eb
parent 1ee461eb4076f287efb22ed5f9dd29d0aecc65a1
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 12 Aug 2016 14:48:17 -0600
t: shorten up test code
Diffstat:
10 files changed, 59 insertions(+), 96 deletions(-)
diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t
@@ -5,11 +5,7 @@ echo 1..5
setup
cat <<EOF > main.c
-int
-main(void)
-{
- return 0;
-}
+int main(void) { return 0; }
EOF
echo "ok 2 - source files wrote"
@@ -33,7 +29,7 @@ Summary:
1 Application link commands
Totals:
- 6 Lines of source code
+ 2 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
diff --git a/t/inst_correct.t b/t/inst_correct.t
@@ -7,9 +7,7 @@ setup
cat <<EOF > fib.c
#include <stdlib.h>
-int
-fibonacci(int n)
-{
+int fibonacci(int n) {
if (n == 0)
return 0;
else if (n == 1)
@@ -18,9 +16,7 @@ fibonacci(int n)
return fibonacci(n - 1) + fibonacci(n - 2);
}
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
int n;
if (argc != 2)
@@ -43,7 +39,7 @@ Summary:
1 Application link commands
Totals:
- 25 Lines of source code
+ 21 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
2 Function definitions
diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t
@@ -1,13 +1,14 @@
#!/bin/sh -e
+#
+# Make sure that do while loop condition instrumentation works.
+#
echo 1..3
. test/utils.sh
setup
cat <<EOF > while.c
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
do {
argc++;
} while (argc != 10);
@@ -16,13 +17,11 @@ main(int argc, char *argv[])
EOF
cat <<EOF > while.c.inst_good
-int
-main(int argc, char *argv[])
-{citrun_start();++_citrun[0];++_citrun[1];++_citrun[2];
+int main(int argc, char *argv[]) {citrun_start();++_citrun[0];
do {
argc++;
- } while ((++_citrun[5], (++_citrun[5], argc != 10)));
- return (++_citrun[6], 0);
+ } while ((++_citrun[3], (++_citrun[3], argc != 10)));
+ return (++_citrun[4], 0);
}
EOF
@@ -36,7 +35,7 @@ Summary:
1 Instrument successes
Totals:
- 9 Lines of source code
+ 7 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -1,15 +1,14 @@
#!/bin/sh -e
+#
+# Test that for loop condition instrumenting works.
+#
echo 1..3
. test/utils.sh
setup
cat <<EOF > for.c
-#include <stdlib.h>
-
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
for (;;);
for (argc = 0; argc < 10; argc++)
@@ -18,14 +17,10 @@ main(int argc, char *argv[])
EOF
cat <<EOF > for.c.inst_good
-#include <stdlib.h>
-
-int
-main(int argc, char *argv[])
-{citrun_start();++_citrun[2];++_citrun[3];++_citrun[4];
+int main(int argc, char *argv[]) {citrun_start();++_citrun[0];
for (;;);
- for ((++_citrun[7], argc = 0); (++_citrun[7], (++_citrun[7], argc < 10)); argc++)
+ for ((++_citrun[3], argc = 0); (++_citrun[3], (++_citrun[3], argc < 10)); argc++)
argv++;
}
EOF
@@ -40,7 +35,7 @@ Summary:
1 Instrument successes
Totals:
- 11 Lines of source code
+ 7 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
diff --git a/t/inst_if.t b/t/inst_if.t
@@ -5,38 +5,30 @@ echo 1..3
setup
cat <<EOF > if.c
-#include <stdlib.h>
-
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
if (argc == 1)
return 1;
else
- exit(14);
+ return(14);
if ((argc = 2))
return 5;
else
- exit(0);
+ return(0);
}
EOF
cat <<EOF > if.c.inst_good
-#include <stdlib.h>
-
-int
-main(int argc, char *argv[])
-{citrun_start();++_citrun[2];++_citrun[3];++_citrun[4];
- if ((++_citrun[5], (++_citrun[5], argc == 1)))
- return (++_citrun[6], 1);
+int main(int argc, char *argv[]) {citrun_start();++_citrun[0];
+ if ((++_citrun[1], (++_citrun[1], argc == 1)))
+ return (++_citrun[2], 1);
else
- (++_citrun[8], exit(14));
+ return(++_citrun[4], (14));
- if ((++_citrun[10], ((++_citrun[10], argc = 2))))
- return (++_citrun[11], 5);
+ if ((++_citrun[6], ((++_citrun[6], argc = 2))))
+ return (++_citrun[7], 5);
else
- (++_citrun[13], exit(0));
+ return(++_citrun[9], (0));
}
EOF
@@ -50,14 +42,13 @@ Summary:
1 Instrument successes
Totals:
- 16 Lines of source code
+ 12 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
2 If statements
- 2 Return statement values
- 2 Call expressions
- 23 Total statements
+ 4 Return statement values
+ 21 Total statements
2 Binary operators
EOF
diff --git a/t/inst_link_multiple.t b/t/inst_link_multiple.t
@@ -7,9 +7,7 @@ setup
cat <<EOF > one.c
void second_func();
-int
-main(void)
-{
+int main(void) {
second_func();
return 0;
}
@@ -18,18 +16,14 @@ EOF
cat <<EOF > two.c
void third_func();
-void
-second_func(void)
-{
+void second_func(void) {
third_func();
return;
}
EOF
cat <<EOF > three.c
-void
-third_func(void)
-{
+void third_func(void) {
return;
}
EOF
@@ -53,7 +47,7 @@ Summary:
1 Application link commands
Totals:
- 24 Lines of source code
+ 18 Lines of source code
96 Lines of instrumentation header
1 Functions called 'main'
3 Function definitions
diff --git a/t/inst_stdout.t b/t/inst_stdout.t
@@ -7,9 +7,7 @@ setup
cat <<EOF > hello.c
#include <stdio.h>
-int
-main(void)
-{
+int main(void) {
printf("hello, world!");
return 0;
}
@@ -27,7 +25,7 @@ Summary:
1 Application link commands
Totals:
- 9 Lines of source code
+ 7 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
diff --git a/t/inst_switch.t b/t/inst_switch.t
@@ -1,13 +1,14 @@
#!/bin/sh -e
+#
+# Make sure that switch statement condition instrumentation works.
+#
echo 1..3
. test/utils.sh
setup
cat <<EOF > switch.c
-int
-main(void)
-{
+int main(void) {
int i;
switch (i) {
@@ -22,19 +23,17 @@ main(void)
EOF
cat <<EOF > switch.c.inst_good
-int
-main(void)
-{citrun_start();++_citrun[0];++_citrun[1];++_citrun[2];
+int main(void) {citrun_start();++_citrun[0];
int i;
- switch ((++_citrun[5], i)) {
+ switch ((++_citrun[3], i)) {
case 0:
break;
case 1:
break;
}
- return (++_citrun[12], 0);
+ return (++_citrun[10], 0);
}
EOF
@@ -48,7 +47,7 @@ Summary:
1 Instrument successes
Totals:
- 15 Lines of source code
+ 13 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
diff --git a/t/inst_two_src.t b/t/inst_two_src.t
@@ -5,17 +5,13 @@ echo 1..3
setup
cat <<EOF > main.c
-int
-main(void)
-{
+int main(void) {
return 0;
}
EOF
cat <<EOF > other.c
-int
-other(void)
-{
+int other(void) {
return 0;
}
EOF
@@ -32,7 +28,7 @@ Summary:
1 Application link commands
Totals:
- 12 Lines of source code
+ 8 Lines of source code
64 Lines of instrumentation header
1 Functions called 'main'
2 Function definitions
diff --git a/t/inst_while.t b/t/inst_while.t
@@ -1,13 +1,14 @@
#!/bin/sh -e
+#
+# Make sure that while loop condition instrumentation works.
+#
echo 1..3
. test/utils.sh
setup
cat <<EOF > while.c
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
while (argc < 17)
argc++;
@@ -17,14 +18,12 @@ main(int argc, char *argv[])
EOF
cat <<EOF > while.c.inst_good
-int
-main(int argc, char *argv[])
-{citrun_start();++_citrun[0];++_citrun[1];++_citrun[2];
- while ((++_citrun[3], (++_citrun[3], argc < 17)))
+int main(int argc, char *argv[]) {citrun_start();++_citrun[0];
+ while ((++_citrun[1], (++_citrun[1], argc < 17)))
argc++;
- while ((++_citrun[6], ((++_citrun[6], argc && argv))));
- return (++_citrun[7], 0);
+ while ((++_citrun[4], ((++_citrun[4], argc && argv))));
+ return (++_citrun[5], 0);
}
EOF
@@ -38,7 +37,7 @@ Summary:
1 Instrument successes
Totals:
- 10 Lines of source code
+ 8 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions