1 package com.puppycrawl.tools.checkstyle.filters; 2 3 import com.puppycrawl.tools.checkstyle.api.CheckstyleException; 4 import com.puppycrawl.tools.checkstyle.api.FilterSet; 5 import com.puppycrawl.tools.checkstyle.filters.SuppressElement; 6 import junit.framework.TestCase; 7 import java.util.regex.PatternSyntaxException ; 8 9 13 public class SuppressionsLoaderTest extends TestCase 14 { 15 public void testNoSuppressions() 16 throws CheckstyleException 17 { 18 final FilterSet fc = 19 SuppressionsLoader.loadSuppressions( 20 System.getProperty("testinputs.dir") 21 + "/suppressions_none.xml"); 22 final FilterSet fc2 = new FilterSet(); 23 assertEquals(fc, fc2); 24 } 25 26 public void testMultipleSuppression() 27 throws CheckstyleException, PatternSyntaxException 28 { 29 final FilterSet fc = 30 SuppressionsLoader.loadSuppressions( 31 System.getProperty("testinputs.dir") 32 + "/suppressions_multiple.xml"); 33 final FilterSet fc2 = new FilterSet(); 34 SuppressElement se0 = new SuppressElement("file0"); 35 se0.setChecks("check0"); 36 fc2.addFilter(se0); 37 SuppressElement se1 = new SuppressElement("file1"); 38 se1.setChecks("check1"); 39 se1.setLines("1,2-3"); 40 fc2.addFilter(se1); 41 SuppressElement se2 = new SuppressElement("file2"); 42 se2.setChecks("check2"); 43 se2.setColumns("1,2-3"); 44 fc2.addFilter(se2); 45 SuppressElement se3 = new SuppressElement("file3"); 46 se3.setChecks("check3"); 47 se3.setLines("1,2-3"); 48 se3.setColumns("1,2-3"); 49 fc2.addFilter(se3); 50 assertEquals(fc, fc2); 51 } 52 53 public void testNoFile() 54 throws CheckstyleException 55 { 56 final String fn = System.getProperty("testinputs.dir") 57 + "/suppressions_no_file.xml"; 58 try { 59 SuppressionsLoader.loadSuppressions(fn); 60 } 61 catch (CheckstyleException ex) { 62 assertEquals( 63 "unable to parse " + fn + " - Attribute \"files\" is required and must be specified for element type \"suppress\".", 64 ex.getMessage()); 65 } 66 } 67 68 public void testNoCheck() 69 throws CheckstyleException 70 { 71 final String fn = System.getProperty("testinputs.dir") 72 + "/suppressions_no_check.xml"; 73 try { 74 SuppressionsLoader.loadSuppressions(fn); 75 } 76 catch (CheckstyleException ex) { 77 assertEquals( 78 "unable to parse " + fn + " - Attribute \"checks\" is required and must be specified for element type \"suppress\".", 79 ex.getMessage()); 80 } 81 } 82 83 public void testBadInt() 84 throws CheckstyleException 85 { 86 final String fn = System.getProperty("testinputs.dir") 87 + "/suppressions_bad_int.xml"; 88 try { 89 SuppressionsLoader.loadSuppressions(fn); 90 } 91 catch (CheckstyleException ex) { 92 assertTrue( 93 ex.getMessage(), 94 ex.getMessage().startsWith("number format exception " + fn + " - ")); 95 } 96 } 97 } 98 | Popular Tags |