opt_v.c revision 1.8
11.8Srillig/* $NetBSD: opt_v.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
21.1Srillig
31.2Srillig/*
41.2Srillig * Tests for the options '-v' and '-nv'.
51.2Srillig *
61.2Srillig * The option '-v' enables verbose mode. It outputs some information about
71.2Srillig * what's going on under the hood, especially when lines are broken. It also
81.2Srillig * outputs a few statistics about line counts and comments at the end.
91.2Srillig *
101.2Srillig * The option '-nv' disables verbose mode. Only errors and warnings are output
111.2Srillig * in this mode, but no progress messages.
121.2Srillig */
131.2Srillig
141.8Srillig//indent input
151.1Srillig/*
161.6Srillig * A block comment.
171.1Srillig */
181.1Srilligvoid
191.1Srilligexample(void)
201.1Srillig{
211.1Srillig	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
221.1Srillig}
231.1Srillig
241.6Srillig/* $ The below comment is neither counted nor formatted. */
251.1Srillig#define macro1 /* prefix */ suffix
261.1Srillig
271.6Srillig/* $ The below comment is formatted and counted. */
281.1Srillig#define macro2 prefix /* suffix */
291.8Srillig//indent end
301.1Srillig
311.8Srillig//indent run -v
321.1Srillig/*
331.6Srillig * A block comment.
341.1Srillig */
351.1Srilligvoid
361.1Srilligexample(void)
371.1Srillig{
381.1Srillig	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
391.1Srillig}
401.1Srillig
411.1Srillig#define macro1 /* prefix */ suffix
421.1Srillig
431.1Srillig#define macro2 prefix		/* suffix */
441.1SrilligThere were 10 output lines and 2 comments
451.1Srillig(Lines with comments)/(Lines with code):  0.571
461.8Srillig//indent end
471.1Srillig
481.5Srillig
491.8Srillig//indent input
501.1Srilligvoid
511.1Srilligexample(void)
521.1Srillig{
531.1Srillig	int sum1 = 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21;
541.1Srillig	int sum2 = (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21);
551.1Srillig}
561.8Srillig//indent end
571.1Srillig
581.8Srillig//indent run -nv
591.1Srilligvoid
601.1Srilligexample(void)
611.1Srillig{
621.1Srillig/* $ XXX: The following lines are too long and should thus be broken. */
631.1Srillig/* $ XXX: If they are broken, -nv does NOT output 'Line broken'. */
641.1Srillig	int		sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
651.1Srillig	int		sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
661.1Srillig}
671.8Srillig//indent end
681.3Srillig
691.3Srillig
701.8Srillig//indent input
711.3Srillig/* Demonstrates line number counting in verbose mode. */
721.3Srillig
731.3Srilligint *function(void)
741.3Srillig{}
751.8Srillig//indent end
761.3Srillig
771.8Srillig//indent run -v
781.3Srillig/* Demonstrates line number counting in verbose mode. */
791.3Srillig
801.3Srilligint *
811.3Srilligfunction(void)
821.3Srillig{
831.3Srillig}
841.3SrilligThere were 5 output lines and 1 comments
851.3Srillig(Lines with comments)/(Lines with code):  0.250
861.8Srillig//indent end
871.3Srillig/* In the above output, the '5' means 5 non-empty lines. */
881.3Srillig
891.3Srillig/*
901.3Srillig * XXX: It's rather strange that -v writes to stdout, even in filter mode.
911.3Srillig * This output belongs on stderr instead.
921.3Srillig */
931.4Srillig
941.4Srillig
951.4Srillig/*
961.4Srillig * Test line counting in preprocessor directives.
971.4Srillig */
981.8Srillig//indent input
991.4Srillig#if 0
1001.4Srilligint line = 1;
1011.4Srilligint line = 2;
1021.4Srilligint line = 3;
1031.4Srillig#else
1041.4Srilligint line = 5;
1051.4Srillig#endif
1061.8Srillig//indent end
1071.4Srillig
1081.8Srillig//indent run -v -di0
1091.4Srillig#if 0
1101.4Srilligint line = 1;
1111.4Srilligint line = 2;
1121.4Srilligint line = 3;
1131.4Srillig#else
1141.4Srilligint line = 5;
1151.4Srillig#endif
1161.4SrilligThere were 3 output lines and 0 comments
1171.4Srillig(Lines with comments)/(Lines with code):  0.000
1181.8Srillig//indent end
1191.4Srillig/*
1201.4Srillig * FIXME: The lines within the conditional compilation directives must be
1211.4Srillig * counted as well. TODO: Move stats out of parser_state.
1221.4Srillig */
123