Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/pub/PubBuildParticipantTest.java |
| =================================================================== |
| --- editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/pub/PubBuildParticipantTest.java (revision 16570) |
| +++ editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/pub/PubBuildParticipantTest.java (working copy) |
| @@ -18,9 +18,12 @@ |
| import com.google.dart.tools.core.internal.builder.TestProjects; |
| import com.google.dart.tools.core.mock.MockContainer; |
| import com.google.dart.tools.core.mock.MockDelta; |
| +import com.google.dart.tools.core.mock.MockFile; |
| +import com.google.dart.tools.core.mock.MockFolder; |
| import static com.google.dart.tools.core.DartCore.PACKAGES_DIRECTORY_NAME; |
| import static com.google.dart.tools.core.DartCore.PUBSPEC_FILE_NAME; |
| +import static com.google.dart.tools.core.DartCore.PUBSPEC_LOCK_FILE_NAME; |
| import static com.google.dart.tools.core.internal.builder.TestProjects.MONITOR; |
| import static com.google.dart.tools.core.internal.builder.TestProjects.newEmptyProject; |
| import static com.google.dart.tools.core.internal.builder.TestProjects.newPubProject1; |
| @@ -28,13 +31,13 @@ |
| import junit.framework.TestCase; |
| import org.eclipse.core.resources.IContainer; |
| +import org.eclipse.core.resources.IProject; |
| +import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import static org.eclipse.core.resources.IResourceDelta.ADDED; |
| import static org.eclipse.core.resources.IResourceDelta.REMOVED; |
| -import java.util.ArrayList; |
| - |
| public class PubBuildParticipantTest extends TestCase { |
| /** |
| @@ -43,39 +46,56 @@ |
| */ |
| private static class Target extends PubBuildParticipant { |
| - private ArrayList<IContainer> actual = new ArrayList<IContainer>(); |
| + private IContainer runPubContainer; |
| + private IResource lockFileProcessed; |
| - public void assertCalls(IContainer... expected) { |
| - if (expected.length == actual.size()) { |
| - boolean success = true; |
| - for (IContainer container : expected) { |
| - if (!actual.contains(container)) { |
| - success = false; |
| - break; |
| - } |
| - } |
| - if (success) { |
| - return; |
| - } |
| + public void assertProcessLockFile(IResource expected) { |
| + boolean success = true; |
| + if (expected != lockFileProcessed) { |
| + success = false; |
| } |
| - PrintStringWriter writer = new PrintStringWriter(); |
| - writer.println("expected:"); |
| - for (IContainer container : expected) { |
| - writer.println(" " + container); |
| + if (success) { |
| + return; |
| } |
| - writer.println("actual:"); |
| - for (IContainer container : actual) { |
| - writer.println(" " + container); |
| + printFailMessage(expected, lockFileProcessed); |
| + |
| + } |
| + |
| + public void assertRunPub(IContainer expected) { |
| + boolean success = true; |
| + if (expected != runPubContainer) { |
| + success = false; |
| } |
| - fail(writer.toString().trim()); |
| + if (success) { |
| + return; |
| + } |
| + printFailMessage(expected, runPubContainer); |
| } |
| @Override |
| + protected void processLockFileContents(IResource lockFile, IProject project, |
| + IProgressMonitor monitor) { |
| + assertNotNull(lockFile); |
| + assertNotNull(project); |
| + assertNotNull(monitor); |
| + lockFileProcessed = lockFile; |
| + } |
| + |
| + @Override |
| protected void runPub(IContainer container, IProgressMonitor monitor) { |
| assertNotNull(container); |
| assertNotNull(monitor); |
| - actual.add(container); |
| + runPubContainer = container; |
| } |
| + |
| + private void printFailMessage(Object expected, Object actual) { |
| + PrintStringWriter writer = new PrintStringWriter(); |
| + writer.println("expected:"); |
| + writer.println(" " + expected); |
| + writer.println("actual:"); |
| + writer.println(" " + actual); |
| + fail(writer.toString().trim()); |
| + } |
| } |
| // Assert pub is not run |
| @@ -84,7 +104,7 @@ |
| MockContainer project = newEmptyProject(); |
| target.build(new BuildEvent(project, null, MONITOR), MONITOR); |
| - target.assertCalls(); |
| + target.assertRunPub(null); |
| } |
| // Assert pub is run on project containing pubspec.yaml |
| @@ -94,9 +114,19 @@ |
| project.addFile(PUBSPEC_FILE_NAME); |
| target.build(new BuildEvent(project, null, MONITOR), MONITOR); |
| - target.assertCalls(project); |
| + target.assertRunPub(project); |
| } |
| + // Assert lock file is processed when changed |
| + public void test_build_full_pub_lockFile() throws Exception { |
| + Target target = new Target(); |
| + MockContainer project = newEmptyProject(); |
| + MockFile file = new MockFile(project, PUBSPEC_LOCK_FILE_NAME); |
| + project.add(file); |
| + target.build(new BuildEvent(project, null, MONITOR), MONITOR); |
| + target.assertProcessLockFile(file); |
| + } |
| + |
| // Assert pub is not run on pubspec.yaml in folder under "packages" directory hierarchy |
| // or in hidden ".svn" directory |
| public void test_build_full_pubInPackages() throws Exception { |
| @@ -104,7 +134,7 @@ |
| MockContainer project = newPubProject1(); |
| target.build(new BuildEvent(project, null, MONITOR), MONITOR); |
| - target.assertCalls(project); |
| + target.assertRunPub(project); |
| } |
| // Assert pub is run when pubspec.yaml is added |
| @@ -116,7 +146,7 @@ |
| delta.add(PUBSPEC_FILE_NAME, ADDED); |
| target.build(new BuildEvent(project, delta, MONITOR), MONITOR); |
| - target.assertCalls(project); |
| + target.assertRunPub(project); |
| } |
| // Assert pub is run when pubspec.yaml has changed |
| @@ -128,7 +158,7 @@ |
| delta.add(PUBSPEC_FILE_NAME); |
| target.build(new BuildEvent(project, delta, MONITOR), MONITOR); |
| - target.assertCalls(project); |
| + target.assertRunPub(project); |
| } |
| // Assert pub is not run on pubspec.yaml in file under "packages" directory hierarchy |
| @@ -142,7 +172,7 @@ |
| delta.add(".svn").add(PUBSPEC_FILE_NAME); |
| target.build(new BuildEvent(project, delta, MONITOR), MONITOR); |
| - target.assertCalls(); |
| + target.assertRunPub(null); |
| } |
| // Assert pub is not run on pubspec.yaml in file under "packages" directory hierarchy |
| @@ -156,7 +186,7 @@ |
| delta.add(".svn").add(PUBSPEC_FILE_NAME); |
| target.build(new BuildEvent(project, delta, MONITOR), MONITOR); |
| - target.assertCalls(); |
| + target.assertRunPub(null); |
| } |
| // Assert pub not is run when pubspec.yaml is removed |
| @@ -168,6 +198,20 @@ |
| delta.add(PUBSPEC_FILE_NAME, REMOVED); |
| target.build(new BuildEvent(project, delta, MONITOR), MONITOR); |
| - target.assertCalls(); |
| + target.assertRunPub(null); |
| } |
| + |
| + // Assert lock file is processed when not in project root |
| + public void test_build_pub_lockFile_notInProjectRoot() throws Exception { |
| + Target target = new Target(); |
| + MockContainer project = newEmptyProject(); |
| + MockFolder myApp = project.addFolder("myapp"); |
| + myApp.addFile(PUBSPEC_FILE_NAME); |
| + MockFile file = new MockFile(myApp, PUBSPEC_LOCK_FILE_NAME); |
| + myApp.add(file); |
| + target.build(new BuildEvent(project, null, MONITOR), MONITOR); |
| + target.assertProcessLockFile(file); |
|
danrubel
2013/01/02 17:21:55
Need to add target.assertRunPub(null) here and oth
keertip
2013/01/02 17:31:38
Done.
|
| + |
| + } |
| + |
| } |