test1185 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <testcase>
  2. <info>
  3. <keywords>
  4. checksrc
  5. </keywords>
  6. </info>
  7. #
  8. # Client-side
  9. <client>
  10. <server>
  11. none
  12. </server>
  13. <name>
  14. checksrc
  15. </name>
  16. <command type="perl">
  17. %SRCDIR/../scripts/checksrc.pl log/code%TESTNUMBER.c
  18. </command>
  19. <file name="log/code%TESTNUMBER.c">
  20. /* test source code
  21. * Violate each rule at least once.
  22. **/
  23. int hello; /*------------------------------------------------------------------*/
  24. int tab;
  25. int trailing_space;
  26. int a = func ();
  27. int b = func( b);
  28. int b = func(b );
  29. func(a, b , c);
  30. int hello()
  31. {
  32. return(2);
  33. }
  34. func(a, b,c);
  35. if(a == 2) {
  36. ;
  37. } else {
  38. moo = 2;
  39. }
  40. if(a == 2){ /* followed by comment */
  41. ;
  42. }
  43. func() ;
  44. a = sprintf(buffer, "%s", moo);
  45. FILE *f = fopen("filename", "r");
  46. void startfunc(int a, int b) {
  47. func();
  48. }
  49. for(;;) {
  50. func(1);
  51. } while(1);
  52. char * name = "hello";
  53. char* name = "hello";
  54. int foo=bar;
  55. int foo= bar;
  56. int foo = bar;
  57. int foo = bar;foo++;
  58. for(;;) {
  59. }
  60. int a = sizeof int;
  61. int a = snprintf(buffer, sizeof(buffer), "%d", 99);
  62. if(a) b++;
  63. // CPP comment?
  64. /* comment doesn't end
  65. </file>
  66. </client>
  67. #
  68. # Verify data after the test has been "shot"
  69. <verify>
  70. <stdout>
  71. ./log/code1185.c:4:82: warning: Longer than 79 columns (LONGLINE)
  72. int hello; /*------------------------------------------------------------------*/
  73. ./log/code1185.c:5:4: error: Contains TAB character (TABS)
  74. int tab;
  75. ^
  76. ./log/code1185.c:7:13: warning: func with space (SPACEBEFOREPAREN)
  77. int a = func ();
  78. ^
  79. ./log/code1185.c:8:14: warning: space after open parenthesis (SPACEAFTERPAREN)
  80. int b = func( b);
  81. ^
  82. ./log/code1185.c:9:16: warning: space before close parenthesis (SPACEBEFORECLOSE)
  83. int b = func(b );
  84. ^
  85. ./log/code1185.c:10:11: warning: space before comma (SPACEBEFORECOMMA)
  86. func(a, b , c);
  87. ^
  88. ./log/code1185.c:14:9: warning: return without space before paren (RETURNNOSPACE)
  89. return(2);
  90. ^
  91. ./log/code1185.c:16:11: warning: comma without following space (COMMANOSPACE)
  92. func(a, b,c);
  93. ^
  94. ./log/code1185.c:18:12: warning: wrongly placed open brace (BRACEPOS)
  95. if(a == 2) {
  96. ^
  97. ./log/code1185.c:20:1: warning: else after closing brace on same line (BRACEELSE)
  98. } else {
  99. ^
  100. ./log/code1185.c:24:11: warning: missing space after close paren (PARENBRACE)
  101. if(a == 2){
  102. ^
  103. ./log/code1185.c:28:7: warning: no space before semicolon (SPACESEMICOLON)
  104. func() ;
  105. ^
  106. ./log/code1185.c:30:5: warning: use of sprintf is banned (BANNEDFUNC)
  107. a = sprintf(buffer, "%s", moo);
  108. ^
  109. ./log/code1185.c:32:11: warning: use of non-binary fopen without FOPEN_* macro: r (FOPENMODE)
  110. FILE *f = fopen("filename", "r");
  111. ^
  112. ./log/code1185.c:34:30: warning: wrongly placed open brace (BRACEPOS)
  113. void startfunc(int a, int b) {
  114. ^
  115. ./log/code1185.c:39:6: warning: not indented 2 steps (uses 4) (INDENTATION)
  116. func(1);
  117. ^
  118. ./log/code1185.c:42:8: warning: space after declarative asterisk (ASTERISKSPACE)
  119. char * name = "hello";
  120. ^
  121. ./log/code1185.c:43:7: warning: space after declarative asterisk (ASTERISKSPACE)
  122. char* name = "hello";
  123. ^
  124. ./log/code1185.c:43:6: warning: no space before asterisk (ASTERISKNOSPACE)
  125. char* name = "hello";
  126. ^
  127. ./log/code1185.c:45:10: warning: no space after equals sign (EQUALSNOSPACE)
  128. int foo=bar;
  129. ^
  130. ./log/code1185.c:46:9: warning: no space before equals sign (NOSPACEEQUALS)
  131. int foo= bar;
  132. ^
  133. ./log/code1185.c:48:16: warning: no space after semicolon (SEMINOSPACE)
  134. int foo = bar;foo++;
  135. ^
  136. ./log/code1185.c:49:10: warning: multiple spaces (MULTISPACE)
  137. for(;;) {
  138. ^
  139. ./log/code1185.c:50:2: warning: not indented 2 steps (uses 0) (INDENTATION)
  140. }
  141. ^
  142. ./log/code1185.c:52:16: warning: sizeof without parenthesis (SIZEOFNOPAREN)
  143. int a = sizeof int;
  144. ^
  145. ./log/code1185.c:53:10: warning: use of snprintf is banned (SNPRINTF)
  146. int a = snprintf(buffer, sizeof(buffer), "%d", 99);
  147. ^
  148. ./log/code1185.c:55:7: warning: conditional block on the same line (ONELINECONDITION)
  149. if(a) b++;
  150. ^
  151. ./log/code1185.c:57:2: warning: // comment (CPPCOMMENTS)
  152. // CPP comment?
  153. ^
  154. ./log/code1185.c:1:1: error: Missing copyright statement (COPYRIGHT)
  155. ^
  156. ./log/code1185.c:1:1: error: Missing closing comment (OPENCOMMENT)
  157. ^
  158. checksrc: 0 errors and 30 warnings
  159. </stdout>
  160. <errorcode>
  161. 5
  162. </errorcode>
  163. </verify>
  164. </testcase>