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.

PropertyFileCLITest.java 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 java.io.File;
  20. import java.io.FileWriter;
  21. import java.io.PrintStream;
  22. import junit.framework.TestCase;
  23. public class PropertyFileCLITest extends TestCase {
  24. public void testPropertyResolution() throws Exception {
  25. File props = File.createTempFile("propertyfilecli", ".properties");
  26. props.deleteOnExit();
  27. FileWriter fw = new FileWriter(props);
  28. fw.write("w=world\nmessage=Hello, ${w}\n");
  29. fw.close();
  30. File build = File.createTempFile("propertyfilecli", ".xml");
  31. build.deleteOnExit();
  32. fw = new FileWriter(build);
  33. fw.write("<project><echo>${message}</echo></project>");
  34. fw.close();
  35. PrintStream sysOut = System.out;
  36. StringBuffer sb = new StringBuffer();
  37. try {
  38. PrintStream out =
  39. new PrintStream(new BuildFileTest.AntOutputStream(sb));
  40. System.setOut(out);
  41. Main m = new NoExitMain();
  42. m.startAnt(new String[] {
  43. "-propertyfile", props.getAbsolutePath(),
  44. "-f", build.getAbsolutePath()
  45. }, null, null);
  46. } finally {
  47. System.setOut(sysOut);
  48. }
  49. String log = sb.toString();
  50. assertTrue("expected log to contain 'Hello, world' but was " + log,
  51. log.indexOf("Hello, world") > -1);
  52. }
  53. private static class NoExitMain extends Main {
  54. protected void exit(int exitCode) {
  55. }
  56. }
  57. }