📄 anttest.java
字号:
public void testOverrideWinsNoInheritAll() { expectLogContaining("test-property-override-no-inheritall-start", "The value of test is 4"); } public void testPropertySet() { executeTarget("test-propertyset"); assertTrue(getLog().indexOf("test1 is ${test1}") > -1); assertTrue(getLog().indexOf("test2 is ${test2}") > -1); assertTrue(getLog().indexOf("test1.x is 1") > -1); } public void testInfiniteLoopViaDepends() { expectBuildException("infinite-loop-via-depends", "recursive call"); } public void testMultiSameProperty() { expectLog("multi-same-property", "prop is two"); } public void testTopLevelTarget() { expectLog("topleveltarget", "Hello world"); } public void testMultiplePropertyFileChildren() { PropertyChecker pcBar = new PropertyChecker("bar", new String[] {null, "Bar"}); PropertyChecker pcFoo = new PropertyChecker("foo", new String[] {null, "Foo"}); project.addBuildListener(pcBar); project.addBuildListener(pcFoo); executeTarget("multiple-property-file-children"); AssertionFailedError aeBar = pcBar.getError(); if (aeBar != null) { throw aeBar; } AssertionFailedError aeFoo = pcFoo.getError(); if (aeFoo != null) { throw aeFoo; } project.removeBuildListener(pcBar); project.removeBuildListener(pcFoo); } public void testBlankTarget() { expectBuildException("blank-target", "target name must not be empty"); } public void testMultipleTargets() { expectLog("multiple-targets", "tadadctbdbtc"); } public void testMultipleTargets2() { expectLog("multiple-targets-2", "dadctb"); } private class BasedirChecker implements BuildListener { private String[] expectedBasedirs; private int calls = 0; private AssertionFailedError error; BasedirChecker(String[] dirs) { expectedBasedirs = dirs; } public void buildStarted(BuildEvent event) {} public void buildFinished(BuildEvent event) {} public void targetFinished(BuildEvent event){} public void taskStarted(BuildEvent event) {} public void taskFinished(BuildEvent event) {} public void messageLogged(BuildEvent event) {} public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { return; } if (error == null) { try { assertEquals(expectedBasedirs[calls++], event.getProject().getBaseDir().getAbsolutePath()); } catch (AssertionFailedError e) { error = e; } } } AssertionFailedError getError() { return error; } } private class ReferenceChecker implements BuildListener { private String[] keys; private boolean[] expectSame; private Object value; private int calls = 0; private AssertionFailedError error; ReferenceChecker(String[] keys, boolean[] expectSame, Object value) { this.keys = keys; this.expectSame = expectSame; this.value = value; } public void buildStarted(BuildEvent event) {} public void buildFinished(BuildEvent event) {} public void targetFinished(BuildEvent event){} public void taskStarted(BuildEvent event) {} public void taskFinished(BuildEvent event) {} public void messageLogged(BuildEvent event) {} public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { return; } if (error == null) { try { String msg = "Call " + calls + " refid=\'" + keys[calls] + "\'"; if (value == null) { Object o = event.getProject().getReference(keys[calls]); if (expectSame[calls++]) { assertNull(msg, o); } else { assertNotNull(msg, o); } } else { // a rather convoluted equals() test Path expect = (Path) value; Path received = (Path) event.getProject().getReference(keys[calls]); boolean shouldBeEqual = expectSame[calls++]; if (received == null) { assertTrue(msg, !shouldBeEqual); } else { String[] l1 = expect.list(); String[] l2 = received.list(); if (l1.length == l2.length) { for (int i=0; i<l1.length; i++) { if (!l1[i].equals(l2[i])) { assertTrue(msg, !shouldBeEqual); } } assertTrue(msg, shouldBeEqual); } else { assertTrue(msg, !shouldBeEqual); } } } } catch (AssertionFailedError e) { error = e; } } } AssertionFailedError getError() { return error; } } private class InputHandlerChecker implements BuildListener { private InputHandler ih; private AssertionFailedError error; InputHandlerChecker(InputHandler value) { ih = value; } public void buildStarted(BuildEvent event) { check(event); } public void buildFinished(BuildEvent event) { check(event); } public void targetFinished(BuildEvent event) { check(event); } public void taskStarted(BuildEvent event) { check(event); } public void taskFinished(BuildEvent event) { check(event); } public void messageLogged(BuildEvent event) { check(event); } public void targetStarted(BuildEvent event) { check(event); } private void check(BuildEvent event) { if (error == null) { try { assertNotNull(event.getProject().getInputHandler()); assertSame(ih, event.getProject().getInputHandler()); } catch (AssertionFailedError e) { error = e; } } } AssertionFailedError getError() { return error; } } private class PropertyChecker implements BuildListener { private String[] expectedValues; private String key; private int calls = 0; private AssertionFailedError error; PropertyChecker(String key, String[] values) { this.key = key; this.expectedValues = values; } public void buildStarted(BuildEvent event) {} public void buildFinished(BuildEvent event) {} public void targetFinished(BuildEvent event){} public void taskStarted(BuildEvent event) {} public void taskFinished(BuildEvent event) {} public void messageLogged(BuildEvent event) {} public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { return; } if (calls >= expectedValues.length) { error = new AssertionFailedError("Unexpected invocation of" + " target " + event.getTarget().getName()); } if (error == null) { try { assertEquals(expectedValues[calls++], event.getProject().getProperty(key)); } catch (AssertionFailedError e) { error = e; } } } AssertionFailedError getError() { return error; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -