Changeset 1162

Show
Ignore:
Timestamp:
05/11/08 14:52:12 (2 months ago)
Author:
fraserofthenight
Message:

It's back to doing exactly what it did before (plus allowing a user-selectable port number)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.unittest/flute/src/org/dsource/descent/flute/flute.d

    r1156 r1162  
    410410                version(inTango) 
    411411                { 
    412                     // TODO 
     412                    TODO(); 
    413413                    AssertException ae = cast(AssertException) e; 
    414414                    assert(ae !is null); 
     
    483483                        return format("%#0.*x", percision, val); 
    484484                    else 
    485                         { } // TANGO 
     485                        { TODO(); } 
    486486                } 
    487487                 
  • trunk/descent.unittest/flute/src/org/dsource/descent/flute/io.d

    r1156 r1162  
    55 * provide socket I/O. 
    66 *  
    7  * The socket will always bind to the localhost, and will opn a port determined 
    8  * by the contents of the ".fluteio" file (without the quotes) in the current 
     7 * 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 
    99 * working directory. This file's sole contents should be an ASCII-encoded 
    1010 * decimal integer between 1024 and 65535m representing the port flute should 
     
    111111             
    112112            public this() 
    113             { 
    114                 writef("Port %s\n", getPort()); 
    115                 exit(EXIT_SUCCESS); 
    116                  
     113            {    
    117114                try 
    118115                { 
     
    125122                catch(SocketException se) 
    126123                { 
    127                     writef("Couldn't create socket; error code %d\n", 
     124                    writef("Couldn't create socket; error code %d\n",  
    128125                        se.errorCode); 
    129126                    exit(se.errorCode); 
  • trunk/descent.unittest/src/descent/internal/unittest/flute/FluteApplicationInstance.java

    r1115 r1162  
    7171     * Initializes the flute application. Should be called only once 
    7272     * 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 
    7578    { 
    7679        assert(fState instanceof StartingUp); 
     
    8184        // Make the connection (interpretation will begin automatically) 
    8285        fConn = new SocketConnection(fPort); 
    83          
    8486        waitStateReturn(); 
    85         assert(((StartingUp) fState).hasCorrectVersion)
     87        boolean retVal = ((StartingUp) fState).hasCorrectVersion
    8688        setState(fWaitingState); 
     89        return retVal; 
    8790    } 
    8891     
  • trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfiguration.java

    r1115 r1162  
    1212package descent.internal.unittest.launcher; 
    1313 
     14import java.io.File; 
     15import java.io.FileWriter; 
    1416import java.io.IOException; 
    1517import java.net.ServerSocket; 
     
    2729 
    2830import descent.core.IJavaElement; 
     31import descent.core.IJavaProject; 
    2932import descent.core.JavaCore; 
    3033import descent.debug.core.AbstractDescentLaunchConfigurationDelegate; 
    3134import descent.debug.core.IDescentLaunchConfigurationConstants; 
    3235import descent.internal.unittest.DescentUnittestPlugin; 
     36import descent.internal.unittest.flute.FluteApplicationInstance; 
    3337import descent.internal.unittest.ui.JUnitMessages; 
    3438import descent.unittest.ITestSpecification; 
     
    4751    public static final String FAILURES_FILENAME_ATTR= DescentUnittestPlugin.PLUGIN_ID+".FAILURENAMES"; //$NON-NLS-1$ 
    4852     
     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     
    4961    @Override 
    5062    public void launch(ILaunchConfiguration config, String mode, 
    5163            ILaunch launch, IProgressMonitor monitor) throws CoreException 
    52     {    
     64    { 
     65        System.out.println(launch.getClass()); 
     66         
    5367        if (monitor == null) 
    5468            monitor = new NullProgressMonitor(); 
     69        boolean shouldKill = false; // Should the process be killed? 
    5570         
    5671        try 
     
    6277            //Find the tests 
    6378            List<ITestSpecification> tests = findTests(config,  
    64                     new SubProgressMonitor(monitor, 60)); 
     79                    new SubProgressMonitor(monitor, 40)); // 40 
    6580            if(tests.isEmpty()) 
    6681                throw error(JUnitMessages.UnittestLaunchConfiguration_no_tests_found); 
     
    7590            if(monitor.isCanceled()) 
    7691                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 
    7898             
    7999            // 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; 
    81102            if(monitor.isCanceled()) 
    82103                return; 
    83104             
     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 
    84123            // Transfer the launch config attributes to the launch 
    85124            launch.setAttribute(IDescentLaunchConfigurationConstants.ATTR_PROJECT_NAME, getProjectName(config)); 
    86             launch.setAttribute(IUnittestLaunchConfigurationAttributes.PORT_ATTR, String.valueOf(port)); 
    87125             
    88126            // 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 
    91131        } 
    92132        finally 
    93133        { 
    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            } 
    95144        } 
    96145    } 
     
    154203                DescentUnittestPlugin.PLUGIN_ID, message)); 
    155204    } 
     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    } 
    156259 
    157260    @Override 
  • trunk/descent.unittest/src/descent/internal/unittest/launcher/UnittestLaunchConfigurationTab.java

    r1115 r1162  
    478478        // TODO get the fluted program executable 
    479479        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$ 
    481481    } 
    482482 
  • trunk/descent.unittest/src/descent/internal/unittest/model/DescentUnittestModel.java

    r1113 r1162  
    4242 
    4343import descent.internal.unittest.DescentUnittestPlugin; 
     44import descent.internal.unittest.flute.FluteApplicationInstance; 
    4445import descent.internal.unittest.launcher.IUnittestLaunchConfigurationAttributes; 
    4546import descent.internal.unittest.ui.JUnitPreferencesConstants; 
     
    193194     * state). 
    194195     */ 
    195     public void notifyLaunch(final ILaunch launch,  
     196    public void notifyLaunch(final ILaunch launch, 
     197            final FluteApplicationInstance app, 
     198            final IJavaProject project, 
    196199            final List<ITestSpecification> tests) 
    197200    { 
    198         ILaunchConfiguration config = launch.getLaunchConfiguration(); 
    199         if (config == null) 
    200             return; 
    201          
    202         // test whether the launch defines the JUnit attributes 
    203         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          
    211201        getDisplay().asyncExec(new Runnable() 
    212202        { 
    213203            public void run() 
    214204            { 
    215                 connectTestRunner(launch, launchedProject, /* TODO port */ 30587, tests); 
     205                connectTestRunner(launch, app, project, tests); 
    216206            } 
    217207        }); 
     
    233223    } 
    234224     
    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) 
    237229    { 
    238230        showTestRunnerViewPartInActivePage(findTestRunnerViewPartInActivePage()); 
     
    250242        } 
    251243 
    252         TestRunSession testRunSession = new TestRunSession(project, port, launch, tests); 
     244        TestRunSession testRunSession = new TestRunSession(project, app, launch, tests); 
    253245        fTestRunSessions.addFirst(testRunSession); 
    254246        notifyTestRunSessionAdded(testRunSession); 
  • trunk/descent.unittest/src/descent/internal/unittest/model/RemoteTestRunnerClient.java

    r1115 r1162  
    3030    private final List<ITestSpecification> tests; 
    3131    private final List<ITestRunListener> listeners; 
    32     private final int port; 
    3332    private boolean stopped = true; 
    3433    private long startTime; 
     
    3635    private FluteApplicationInstance app; 
    3736     
    38     public RemoteTestRunnerClient(int $port, List<ITestSpecification> $tests, 
     37    public RemoteTestRunnerClient(FluteApplicationInstance $app, 
     38            List<ITestSpecification> $tests, 
    3939            List<ITestRunListener> $listeners) 
    4040    { 
    41         port = $port
     41        app = $app
    4242        tests = $tests; 
    4343        listeners = $listeners; 
     
    5757    { 
    5858        return app.isConnected(); 
    59     } 
    60      
    61     public void init() 
    62     {        
    63         if(isRunning()) 
    64             return; 
    65          
    66         try 
    67         { 
    68             synchronized(this) 
    69             { 
    70                 app = new FluteApplicationInstance(port); 
    71             } 
    72             app.init(); 
    73         } 
    74         catch(IOException e) 
    75         { 
    76         } 
    7759    } 
    7860     
  • trunk/descent.unittest/src/descent/internal/unittest/model/TestRunSession.java

    r1048 r1162  
    2626import descent.core.ICompilationUnit; 
    2727import descent.core.IJavaProject; 
     28import descent.internal.unittest.flute.FluteApplicationInstance; 
    2829import descent.internal.unittest.model.TestElement.Status; 
    2930 
     
    9394     
    9495 
    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); 
    98100        assert(null != testedProject); 
    99101        assert(null != launch); 
     
    113115        fTotalCount = 0; 
    114116         
    115         // Add the run listener that translates tuff to the session listeners 
     117        // Add the run listener that translates stuff to the session listeners 
    116118        List<ITestRunListener> listeners = new ArrayList<ITestRunListener>(); 
    117119        listeners.add(new TestSessionNotifier()); 
    118120         
    119         fTestRunnerClient= new RemoteTestRunnerClient(port, tests, listeners); 
     121        fTestRunnerClient= new RemoteTestRunnerClient(app, tests, listeners); 
    120122        fSessionListeners= new ListenerList(); 
    121123         
     
    126128                { 
    127129                    createTestTree(tests); 
    128                     fTestRunnerClient.init(); 
    129130                    if(fTestRunnerClient.isConnected()) 
    130131                        fTestRunnerClient.run(); 
  • trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.java

    r1115 r1162  
    8282    public static String TestRunnerViewPart_wrapperJobName; 
    8383    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; 
    8488    public static String UnittestLaunchConfiguration_invalid_port; 
    8589    public static String UnittestLaunchConfiguration_no_open_port; 
    8690    public static String UnittestLaunchConfiguration_no_tests_found; 
     91    public static String UnittestLaunchConfiguration_program_does_not_exist; 
    8792    public static String UnittestLaunchConfiguration_task_name; 
    8893    public static String UnittestLaunchConfigurationTab_default_package; 
  • trunk/descent.unittest/src/descent/internal/unittest/ui/JUnitMessages.properties

    r1115 r1162  
    7575UnittestLaunchConfiguration_no_tests_found=No tests were found in the given launch container 
    7676UnittestLaunchConfiguration_container_not_found=Launch container could not be found 
     77UnittestLaunchConfiguration_could_not_connect=Error connecting to fluted application: %1$s 
     78UnittestLaunchConfiguration_could_not_delete_file=Error creating port file: Could not delete existing file %1$s 
     79UnittestLaunchConfiguration_error_crearing_file=Error creating port file: %1$s 
     80UnittestLaunchConfiguration_error_writing_file=Error writing port to file: %1$s 
    7781UnittestLaunchConfigurationTab_group_test_selection=Test selection 
    7882UnittestLaunchConfigurationTab_dialog_test_container_selection=Test container selection 
     
    8084UnittestLaunchConfigurationTab_error_test_container_does_not_exist=Test container does not exist 
    8185UnittestLaunchConfigurationTab_error_invalid_port=Invalid port number 
     86UnittestLaunchConfiguration_program_does_not_exist=Program file does not exist 
    8287UnittestLaunchConfigurationTab_error_port_number=Port must be between 1024 and 65535 
    8388UnittestLaunchConfigurationTab_tab_label=Test 
  • trunk/descent.unittest/src/descent/internal/unittest/ui/OpenModuleAction.java

    r1156 r1162  
    6060         
    6161        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$ 
    6464                moduleSignature.substring(index + 1) : moduleSignature); 
    6565         
  • 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.lib 
     1dmd -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  
    5757unittest 
    5858{ 
     59    throwAnException(); 
     60} 
     61 
     62void throwAnException() 
     63{ 
     64    // Another couple lines to test line info 
     65     
     66     
     67     
     68    doTheThrowing(); 
     69} 
     70 
     71void doTheThrowing() 
     72{ 
     73    // More blank lines 
     74     
     75     
     76     
    5977    throw new ArgumentException("NO WAI!"); 
    6078}