Changeset 122

Show
Ignore:
Timestamp:
03/02/08 19:21:47 (10 months ago)
Author:
iteman
Message:

- Added support for autotest by -a option. (Ticket #10)

Location:
trunk/src/Stagehand
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Stagehand/TestRunner.php

    r121 r122  
    3737 
    3838require_once 'Console/Getopt.php'; 
     39require_once 'Stagehand/TestRunner/AlterationMonitor.php'; 
    3940 
    4041// {{{ Stagehand_TestRunner 
     
    161162            $runner->run($suite, $color); 
    162163        } else { 
    163             if (php_uname('s') !== 'Windows NT') { 
    164                 echo "ERROR: -a option is not supported for your platform.\n"; 
    165                 self::_displayUsage(); 
    166                 return 1; 
    167             } 
    168  
    169164            $directory = realpath($directory); 
    170165            if ($directory === false || !is_dir($directory)) { 
     
    211206            $options[] = $directory; 
    212207 
    213             define('FILE_NOTIFY_CHANGE_FILE_NAME',    0x00000001); 
    214             define('FILE_NOTIFY_CHANGE_DIR_NAME',     0x00000002); 
    215             define('FILE_NOTIFY_CHANGE_ATTRIBUTES',   0x00000004); 
    216             define('FILE_NOTIFY_CHANGE_SIZE',         0x00000008); 
    217             define('FILE_NOTIFY_CHANGE_LAST_WRITE',   0x00000010); 
    218             define('FILE_NOTIFY_CHANGE_LAST_ACCESS',  0x00000020); 
    219             define('FILE_NOTIFY_CHANGE_CREATION',     0x00000040); 
    220             define('FILE_NOTIFY_CHANGE_EA',           0x00000080); 
    221             define('FILE_NOTIFY_CHANGE_SECURITY',     0x00000100); 
    222             define('FILE_NOTIFY_CHANGE_STREAM_NAME',  0x00000200); 
    223             define('FILE_NOTIFY_CHANGE_STREAM_SIZE',  0x00000400); 
    224             define('FILE_NOTIFY_CHANGE_STREAM_WRITE', 0x00000800); 
    225             define('INFINITE', 0xffffffff); 
    226  
    227             $kernel32 = wb_load_library('kernel32.dll'); 
    228             while (true) { 
    229                 $h1 = wb_call_function(wb_get_function_address('FindFirstChangeNotification', $kernel32), 
    230                                        array($directory, 
    231                                              1, 
    232                                              FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_EA | FILE_NOTIFY_CHANGE_SECURITY) 
    233                                        ); 
    234  
    235                 print "Waiting for changes in the directory [ $directory ] ...\n"; 
    236                 $h2 = wb_call_function(wb_get_function_address('WaitForSingleObject', $kernel32), 
    237                                        array($h1, INFINITE) 
    238                                        ); 
    239                 passthru("$command " . implode(' ', $options), $result); 
    240  
    241                 $h3 = wb_call_function(wb_get_function_address('FindCloseChangeNotification', $kernel32), 
    242                                        array($h1) 
    243                                        ); 
    244  
    245                 if ($result !== 0) { 
    246                     return 1; 
    247                 } 
     208            $monitor = new Stagehand_TestRunner_AlterationMonitor($directory, "$command " . implode(' ', $options)); 
     209 
     210            try { 
     211                $monitor->monitor(); 
     212            } catch (Stagehand_TestRunner_Exception $e) { 
     213                echo 'ERROR: ' . $e->getMessage() . "\n"; 
     214                return 1; 
    248215            } 
    249216        } 
     
    281248  -c        color the result of a test runner run 
    282249  -p <file> preload <file> as a PHP script 
    283   -a        watch for changes in a specified directory and run all tests in 
     250  -a        watch for changes in a specified directory and run tests in 
    284251            the directory recursively when changes are detected (autotest) 
    285252