You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultLoggerTest.java 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant;
  19. import org.apache.tools.ant.util.StringUtils;
  20. import org.junit.Test;
  21. import java.io.PrintWriter;
  22. import static org.junit.Assert.assertEquals;
  23. public class DefaultLoggerTest {
  24. private static String msg(Throwable error, boolean verbose) {
  25. StringBuffer m = new StringBuffer();
  26. DefaultLogger.throwableMessage(m, error, verbose);
  27. return m.toString();
  28. }
  29. @SuppressWarnings("serial")
  30. @Test
  31. public void testThrowableMessage() { // #43398
  32. BuildException be = new BuildException("oops", new Location("build.xml", 1, 0));
  33. assertEquals(
  34. "build.xml:1: oops" + StringUtils.LINE_SEP,
  35. msg(be, false));
  36. be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0));
  37. assertEquals(
  38. "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
  39. "build.xml:1: oops" + StringUtils.LINE_SEP,
  40. msg(be, false));
  41. be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 3, 0));
  42. assertEquals(
  43. "build.xml:3: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
  44. "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
  45. "build.xml:1: oops" + StringUtils.LINE_SEP,
  46. msg(be, false));
  47. Exception x = new Exception("problem") {
  48. public void printStackTrace(PrintWriter w) {
  49. w.println("problem");
  50. w.println(" at p.C.m");
  51. }
  52. };
  53. assertEquals(
  54. "problem" + StringUtils.LINE_SEP +
  55. " at p.C.m" + StringUtils.LINE_SEP,
  56. msg(x, false));
  57. be = new BuildException(x, new Location("build.xml", 1, 0));
  58. assertEquals(
  59. "build.xml:1: problem" + StringUtils.LINE_SEP +
  60. " at p.C.m" + StringUtils.LINE_SEP,
  61. msg(be, false));
  62. be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0));
  63. assertEquals(
  64. "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP +
  65. "build.xml:1: problem" + StringUtils.LINE_SEP +
  66. " at p.C.m" + StringUtils.LINE_SEP,
  67. msg(be, false));
  68. }
  69. }