opt_v.c revision 1.5
1/* $NetBSD: opt_v.c,v 1.5 2021/11/20 11:13:18 rillig Exp $ */ 2/* $FreeBSD$ */ 3 4/* 5 * Tests for the options '-v' and '-nv'. 6 * 7 * The option '-v' enables verbose mode. It outputs some information about 8 * what's going on under the hood, especially when lines are broken. It also 9 * outputs a few statistics about line counts and comments at the end. 10 * 11 * The option '-nv' disables verbose mode. Only errors and warnings are output 12 * in this mode, but no progress messages. 13 */ 14 15#indent input 16/* 17 * A long comment. 18 */ 19void 20example(void) 21{ 22 printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third"); 23} 24 25/* $ This comment is neither counted nor formatted. */ 26#define macro1 /* prefix */ suffix 27 28/* $ This comment is formatted and counted. */ 29#define macro2 prefix /* suffix */ 30#indent end 31 32#indent run -v 33/* 34 * A long comment. 35 */ 36void 37example(void) 38{ 39 printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third"); 40} 41 42#define macro1 /* prefix */ suffix 43 44#define macro2 prefix /* suffix */ 45There were 10 output lines and 2 comments 46(Lines with comments)/(Lines with code): 0.571 47#indent end 48 49 50#indent input 51void 52example(void) 53{ 54 int sum1 = 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21; 55 int sum2 = (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21); 56} 57#indent end 58 59#indent run -nv 60void 61example(void) 62{ 63/* $ XXX: The following lines are too long and should thus be broken. */ 64/* $ XXX: If they are broken, -nv does NOT output 'Line broken'. */ 65 int sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21; 66 int sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21); 67} 68#indent end 69 70 71#indent input 72/* Demonstrates line number counting in verbose mode. */ 73 74int *function(void) 75{} 76#indent end 77 78#indent run -v 79/* Demonstrates line number counting in verbose mode. */ 80 81int * 82function(void) 83{ 84} 85There were 5 output lines and 1 comments 86(Lines with comments)/(Lines with code): 0.250 87#indent end 88/* In the above output, the '5' means 5 non-empty lines. */ 89 90/* 91 * XXX: It's rather strange that -v writes to stdout, even in filter mode. 92 * This output belongs on stderr instead. 93 */ 94 95 96/* 97 * Test line counting in preprocessor directives. 98 */ 99#indent input 100#if 0 101int line = 1; 102int line = 2; 103int line = 3; 104#else 105int line = 5; 106#endif 107#indent end 108 109#indent run -v -di0 110#if 0 111int line = 1; 112int line = 2; 113int line = 3; 114#else 115int line = 5; 116#endif 117There were 3 output lines and 0 comments 118(Lines with comments)/(Lines with code): 0.000 119#indent end 120/* 121 * FIXME: The lines within the conditional compilation directives must be 122 * counted as well. TODO: Move stats out of parser_state. 123 */ 124