Changeset 1162
- Timestamp:
- 05/11/08 14:52:12 (2 months ago)
- Files:
-
- trunk/descent.unittest/flute/src/org/dsource/descent/flute/flute.d (modified) (2 diffs)
- trunk/descent.unittest/flute/src/org/dsource/descent/flute/io.d (modified) (3 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/flute/FluteApplicationInstance.java (modified) (2 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfiguration.java (modified) (6 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfigurationTab.java (modified) (1 diff)
- trunk/descent.unittest/src/descent/internal/unittest/model/DescentUnittestModel.java (modified) (4 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/model/RemoteTestRunnerClient.java (modified) (3 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/model/TestRunSession.java (modified) (4 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.java (modified) (1 diff)
- trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.properties (modified) (2 diffs)
- trunk/descent.unittest/src/descent/internal/unittest/ui/OpenModuleAction.java (modified) (1 diff)
- trunk/descent.unittest/testdata/src/compile.bat (modified) (1 diff)
- trunk/descent.unittest/testdata/src/sample/module1.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.unittest/flute/src/org/dsource/descent/flute/flute.d
r1156 r1162 410 410 version(inTango) 411 411 { 412 // TODO412 TODO(); 413 413 AssertException ae = cast(AssertException) e; 414 414 assert(ae !is null); … … 483 483 return format("%#0.*x", percision, val); 484 484 else 485 { } // TANGO485 { TODO(); } 486 486 } 487 487 trunk/descent.unittest/flute/src/org/dsource/descent/flute/io.d
r1156 r1162 5 5 * provide socket I/O. 6 6 * 7 * The socket will always bind to the localhost, and will op n a port determined8 * by the contents of the ".flute io" file (without the quotes) in the current7 * The socket will always bind to the localhost, and will open a port determined 8 * by the contents of the ".fluteport" file (without the quotes) in the current 9 9 * working directory. This file's sole contents should be an ASCII-encoded 10 10 * decimal integer between 1024 and 65535m representing the port flute should … … 111 111 112 112 public this() 113 { 114 writef("Port %s\n", getPort()); 115 exit(EXIT_SUCCESS); 116 113 { 117 114 try 118 115 { … … 125 122 catch(SocketException se) 126 123 { 127 writef("Couldn't create socket; error code %d\n", 124 writef("Couldn't create socket; error code %d\n", 128 125 se.errorCode); 129 126 exit(se.errorCode); trunk/descent.unittest/src/descent/internal/unittest/flute/FluteApplicationInstance.java
r1115 r1162 71 71 * Initializes the flute application. Should be called only once 72 72 * and before any calls to other methods. 73 */ 74 public void init() throws IOException 73 * 74 * @return true if and only if the connection was successfully made. If a 75 * was encountered, the instance should be killed instantly. 76 */ 77 public boolean init() throws IOException 75 78 { 76 79 assert(fState instanceof StartingUp); … … 81 84 // Make the connection (interpretation will begin automatically) 82 85 fConn = new SocketConnection(fPort); 83 84 86 waitStateReturn(); 85 assert(((StartingUp) fState).hasCorrectVersion);87 boolean retVal = ((StartingUp) fState).hasCorrectVersion; 86 88 setState(fWaitingState); 89 return retVal; 87 90 } 88 91 trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfiguration.java
r1115 r1162 12 12 package descent.internal.unittest.launcher; 13 13 14 import java.io.File; 15 import java.io.FileWriter; 14 16 import java.io.IOException; 15 17 import java.net.ServerSocket; … … 27 29 28 30 import descent.core.IJavaElement; 31 import descent.core.IJavaProject; 29 32 import descent.core.JavaCore; 30 33 import descent.debug.core.AbstractDescentLaunchConfigurationDelegate; 31 34 import descent.debug.core.IDescentLaunchConfigurationConstants; 32 35 import descent.internal.unittest.DescentUnittestPlugin; 36 import descent.internal.unittest.flute.FluteApplicationInstance; 33 37 import descent.internal.unittest.ui.JUnitMessages; 34 38 import descent.unittest.ITestSpecification; … … 47 51 public static final String FAILURES_FILENAME_ATTR= DescentUnittestPlugin.PLUGIN_ID+".FAILURENAMES"; //$NON-NLS-1$ 48 52 53 /** 54 * The file to create next to the fluted executable to use to find the port. 55 * This is a hack because it's impossible to pass command-line arguments to 56 * the program (well, it's not, but this might be easier than finding the 57 * stack frame and trying to read the arguments like that). 58 */ 59 public static final String PORT_FILENAME = ".fluteport"; //$NON-NLS-1$ 60 49 61 @Override 50 62 public void launch(ILaunchConfiguration config, String mode, 51 63 ILaunch launch, IProgressMonitor monitor) throws CoreException 52 { 64 { 65 System.out.println(launch.getClass()); 66 53 67 if (monitor == null) 54 68 monitor = new NullProgressMonitor(); 69 boolean shouldKill = false; // Should the process be killed? 55 70 56 71 try … … 62 77 //Find the tests 63 78 List<ITestSpecification> tests = findTests(config, 64 new SubProgressMonitor(monitor, 60));79 new SubProgressMonitor(monitor, 40)); // 40 65 80 if(tests.isEmpty()) 66 81 throw error(JUnitMessages.UnittestLaunchConfiguration_no_tests_found); … … 75 90 if(monitor.isCanceled()) 76 91 return; 77 monitor.worked(5); 92 93 // Create the file with the port 94 String portFilePath = getPortFilePath(config); 95 File portFile = createFile(portFilePath); 96 writeToFile(Integer.toString(port), portFile); 97 monitor.worked(15); // 55 78 98 79 99 // Launch the applicataion 80 super.launch(config, mode, launch, new SubProgressMonitor(monitor, 30)); 100 super.launch(config, mode, launch, new SubProgressMonitor(monitor, 20)); // 75 101 shouldKill = true; 81 102 if(monitor.isCanceled()) 82 103 return; 83 104 105 // Connect to the application 106 FluteApplicationInstance app; 107 try 108 { 109 synchronized(this) 110 { 111 app = new FluteApplicationInstance(port); 112 } 113 app.init(); 114 } 115 catch(IOException e) 116 { 117 throw error(String.format(JUnitMessages.UnittestLaunchConfiguration_could_not_connect, e.getMessage())); 118 } 119 monitor.worked(20); // 95 120 if(monitor.isCanceled()) 121 return; 122 84 123 // Transfer the launch config attributes to the launch 85 124 launch.setAttribute(IDescentLaunchConfigurationConstants.ATTR_PROJECT_NAME, getProjectName(config)); 86 launch.setAttribute(IUnittestLaunchConfigurationAttributes.PORT_ATTR, String.valueOf(port));87 125 88 126 // Start the Descent side of things 89 DescentUnittestPlugin.getModel().notifyLaunch(launch, tests); 90 monitor.worked(5); 127 IJavaProject project = verifyJavaProject(config); 128 DescentUnittestPlugin.getModel().notifyLaunch(launch, app, project, tests); 129 shouldKill = false; 130 monitor.worked(5); // 100 91 131 } 92 132 finally 93 133 { 94 monitor.done(); 134 monitor.done(); 135 if(shouldKill) 136 { 137 try 138 { 139 if(launch.canTerminate()) 140 launch.terminate(); 141 } 142 catch(Exception e) { } // Don't throw from finally 143 } 95 144 } 96 145 } … … 154 203 DescentUnittestPlugin.PLUGIN_ID, message)); 155 204 } 205 206 private static File createFile(String path) throws CoreException 207 { 208 File file = new File(path); 209 if(file.exists()) 210 { 211 if(!file.delete()) 212 { 213 throw error(String.format(JUnitMessages.UnittestLaunchConfiguration_could_not_delete_file, path)); 214 } 215 } 216 try 217 { 218 file.createNewFile(); 219 } 220 catch(IOException e) 221 { 222 throw error(String.format(JUnitMessages.UnittestLaunchConfiguration_error_crearing_file, e.getMessage())); 223 } 224 return file; 225 } 226 227 private static void writeToFile(String str, File file) throws CoreException 228 { 229 try 230 { 231 FileWriter writer = new FileWriter(file); 232 writer.append(str); 233 writer.flush(); 234 writer.close(); 235 } 236 catch(IOException e) 237 { 238 throw error(String.format(JUnitMessages.UnittestLaunchConfiguration_error_writing_file, e.getMessage())); 239 } 240 } 241 242 private String getPortFilePath(ILaunchConfiguration config) throws CoreException 243 { 244 File dirFile = verifyWorkingDirectory(config); 245 String dirPath; 246 if(null != dirFile) 247 { 248 dirPath = dirFile.getPath(); 249 } 250 else 251 { 252 File exe = new File(verifyProgramPath(config).toOSString()); 253 if(!exe.exists() || !exe.isFile()) 254 throw error(JUnitMessages.UnittestLaunchConfiguration_program_does_not_exist); 255 dirPath = exe.getParent(); 256 } 257 return dirPath + File.separator + PORT_FILENAME; 258 } 156 259 157 260 @Override trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfigurationTab.java
r1115 r1162 478 478 // TODO get the fluted program executable 479 479 config.setAttribute(IDescentLaunchConfigurationConstants.ATTR_PROGRAM_NAME, 480 "C:/ Users/xycos/workspace/descent.unittest/testdata/bin/test.exe"); //$NON-NLS-1$480 "C:/workspace/descent.unittest/testdata/bin/test.exe"); //$NON-NLS-1$ 481 481 } 482 482 trunk/descent.unittest/src/descent/internal/unittest/model/DescentUnittestModel.java
r1113 r1162 42 42 43 43 import descent.internal.unittest.DescentUnittestPlugin; 44 import descent.internal.unittest.flute.FluteApplicationInstance; 44 45 import descent.internal.unittest.launcher.IUnittestLaunchConfigurationAttributes; 45 46 import descent.internal.unittest.ui.JUnitPreferencesConstants; … … 193 194 * state). 194 195 */ 195 public void notifyLaunch(final ILaunch launch, 196 public void notifyLaunch(final ILaunch launch, 197 final FluteApplicationInstance app, 198 final IJavaProject project, 196 199 final List<ITestSpecification> tests) 197 200 { 198 ILaunchConfiguration config = launch.getLaunchConfiguration();199 if (config == null)200 return;201 202 // test whether the launch defines the JUnit attributes203 String portStr = launch.getAttribute(IUnittestLaunchConfigurationAttributes.PORT_ATTR);204 String projectStr = launch.getAttribute(IDescentLaunchConfigurationConstants.ATTR_PROJECT_NAME);205 if (portStr == null || projectStr == null)206 return;207 208 final int port = Integer.parseInt(portStr);209 final IJavaProject launchedProject = getJavaProject(projectStr);210 211 201 getDisplay().asyncExec(new Runnable() 212 202 { 213 203 public void run() 214 204 { 215 connectTestRunner(launch, launchedProject, /* TODO port */ 30587, tests);205 connectTestRunner(launch, app, project, tests); 216 206 } 217 207 }); … … 233 223 } 234 224 235 private void connectTestRunner(ILaunch launch, IJavaProject project, 236 int port, List<ITestSpecification> tests) 225 private void connectTestRunner(ILaunch launch, 226 FluteApplicationInstance app, 227 IJavaProject project, 228 List<ITestSpecification> tests) 237 229 { 238 230 showTestRunnerViewPartInActivePage(findTestRunnerViewPartInActivePage()); … … 250 242 } 251 243 252 TestRunSession testRunSession = new TestRunSession(project, port, launch, tests);244 TestRunSession testRunSession = new TestRunSession(project, app, launch, tests); 253 245 fTestRunSessions.addFirst(testRunSession); 254 246 notifyTestRunSessionAdded(testRunSession); trunk/descent.unittest/src/descent/internal/unittest/model/RemoteTestRunnerClient.java
r1115 r1162 30 30 private final List<ITestSpecification> tests; 31 31 private final List<ITestRunListener> listeners; 32 private final int port;33 32 private boolean stopped = true; 34 33 private long startTime; … … 36 35 private FluteApplicationInstance app; 37 36 38 public RemoteTestRunnerClient(int $port, List<ITestSpecification> $tests, 37 public RemoteTestRunnerClient(FluteApplicationInstance $app, 38 List<ITestSpecification> $tests, 39 39 List<ITestRunListener> $listeners) 40 40 { 41 port = $port;41 app = $app; 42 42 tests = $tests; 43 43 listeners = $listeners; … … 57 57 { 58 58 return app.isConnected(); 59 }60 61 public void init()62 {63 if(isRunning())64 return;65 66 try67 {68 synchronized(this)69 {70 app = new FluteApplicationInstance(port);71 }72 app.init();73 }74 catch(IOException e)75 {76 }77 59 } 78 60 trunk/descent.unittest/src/descent/internal/unittest/model/TestRunSession.java
r1048 r1162 26 26 import descent.core.ICompilationUnit; 27 27 import descent.core.IJavaProject; 28 import descent.internal.unittest.flute.FluteApplicationInstance; 28 29 import descent.internal.unittest.model.TestElement.Status; 29 30 … … 93 94 94 95 95 public TestRunSession(IJavaProject testedProject, int port, ILaunch launch, 96 final List<ITestSpecification> tests) 97 { 96 public TestRunSession(IJavaProject testedProject, FluteApplicationInstance app, 97 ILaunch launch, final List<ITestSpecification> tests) 98 { 99 assert(null != app); 98 100 assert(null != testedProject); 99 101 assert(null != launch); … … 113 115 fTotalCount = 0; 114 116 115 // Add the run listener that translates tuff to the session listeners117 // Add the run listener that translates stuff to the session listeners 116 118 List<ITestRunListener> listeners = new ArrayList<ITestRunListener>(); 117 119 listeners.add(new TestSessionNotifier()); 118 120 119 fTestRunnerClient= new RemoteTestRunnerClient( port, tests, listeners);121 fTestRunnerClient= new RemoteTestRunnerClient(app, tests, listeners); 120 122 fSessionListeners= new ListenerList(); 121 123 … … 126 128 { 127 129 createTestTree(tests); 128 fTestRunnerClient.init();129 130 if(fTestRunnerClient.isConnected()) 130 131 fTestRunnerClient.run(); trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.java
r1115 r1162 82 82 public static String TestRunnerViewPart_wrapperJobName; 83 83 public static String UnittestLaunchConfiguration_container_not_found; 84 public static String UnittestLaunchConfiguration_could_not_connect; 85 public static String UnittestLaunchConfiguration_could_not_delete_file; 86 public static String UnittestLaunchConfiguration_error_crearing_file; 87 public static String UnittestLaunchConfiguration_error_writing_file; 84 88 public static String UnittestLaunchConfiguration_invalid_port; 85 89 public static String UnittestLaunchConfiguration_no_open_port; 86 90 public static String UnittestLaunchConfiguration_no_tests_found; 91 public static String UnittestLaunchConfiguration_program_does_not_exist; 87 92 public static String UnittestLaunchConfiguration_task_name; 88 93 public static String UnittestLaunchConfigurationTab_default_package; trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.properties
r1115 r1162 75 75 UnittestLaunchConfiguration_no_tests_found=No tests were found in the given launch container 76 76 UnittestLaunchConfiguration_container_not_found=Launch container could not be found 77 UnittestLaunchConfiguration_could_not_connect=Error connecting to fluted application: %1$s 78 UnittestLaunchConfiguration_could_not_delete_file=Error creating port file: Could not delete existing file %1$s 79 UnittestLaunchConfiguration_error_crearing_file=Error creating port file: %1$s 80 UnittestLaunchConfiguration_error_writing_file=Error writing port to file: %1$s 77 81 UnittestLaunchConfigurationTab_group_test_selection=Test selection 78 82 UnittestLaunchConfigurationTab_dialog_test_container_selection=Test container selection … … 80 84 UnittestLaunchConfigurationTab_error_test_container_does_not_exist=Test container does not exist 81 85 UnittestLaunchConfigurationTab_error_invalid_port=Invalid port number 86 UnittestLaunchConfiguration_program_does_not_exist=Program file does not exist 82 87 UnittestLaunchConfigurationTab_error_port_number=Port must be between 1024 and 65535 83 88 UnittestLaunchConfigurationTab_tab_label=Test trunk/descent.unittest/src/descent/internal/unittest/ui/OpenModuleAction.java
r1156 r1162 60 60 61 61 int index = moduleSignature.lastIndexOf('.'); 62 String packagePart = index > 0 ? moduleSignature.substring(0, index) : ""; 63 String modulePart = String.format("%1$s.d", index > 0 ? 62 String packagePart = index > 0 ? moduleSignature.substring(0, index) : ""; //$NON-NLS-1$ 63 String modulePart = String.format("%1$s.d", index > 0 ? //$NON-NLS-1$ 64 64 moduleSignature.substring(index + 1) : moduleSignature); 65 65 trunk/descent.unittest/testdata/src/compile.bat
r1156 r1162 1 dmd -g -unittest - version=FluteCommandLine -of..\bin\test sample\module1.d sample\foo\module3.d sample\foo\bar\module2.d ..\..\flute\src\cn\kuehne\flectioned.d ..\..\flute\src\org\dsource\descent\flute\flute.d ..\..\flute\src\org\dsource\descent\flute\io.d -IC:\dmd\src\phobos C:\d\dmd\lib\WS2_32.lib1 dmd -g -unittest -of..\bin\test sample\module1.d sample\foo\module3.d sample\foo\bar\module2.d ..\..\flute\src\cn\kuehne\flectioned.d ..\..\flute\src\org\dsource\descent\flute\flute.d ..\..\flute\src\org\dsource\descent\flute\io.d -IC:\dmd\src\phobos C:\d\dmd\lib\WS2_32.lib trunk/descent.unittest/testdata/src/sample/module1.d
r1052 r1162 57 57 unittest 58 58 { 59 throwAnException(); 60 } 61 62 void throwAnException() 63 { 64 // Another couple lines to test line info 65 66 67 68 doTheThrowing(); 69 } 70 71 void doTheThrowing() 72 { 73 // More blank lines 74 75 76 59 77 throw new ArgumentException("NO WAI!"); 60 78 }
