piece / stagehand-testrunner

A continuous test runner for CLI
https://github.com/piece/stagehand-testrunner/wiki
BSD 2-Clause "Simplified" License
35 stars 12 forks source link

Tests run 2 times after only 1 file has been updated. #50

Closed smori1983 closed 8 years ago

smori1983 commented 9 years ago

When I execute testrunner with -a (autotest mode) , sometimes tests run 2 times just after I saved a file. I don't update any other files in the same time, I expect tests run only 1 time.

environment: VirtualBox os: CentOS 6.5 editor: vim

Part of ~/.vimrc:

set directory=~/.vim/swp
set backupdir=~/.vim/tmp

autotest モードでtestrunnerを実行している時、1ファイルを保存した直後にテストが2回連続で実行されることがあります。

smori1983 commented 9 years ago

I tried to debug which file is detected as changed, by writing code as follows, to Stagehand/AlterationMonitor/AlterationMonitor.php which testrunner depends.

AlterationMonitor::waitForChanges()

                if (count($this->resourceChangeEvents)) {

                    foreach ($this->resourceChangeEvents as $event) {
                        switch ($event->getType()) {
                            case 1: $type = 'CREATED'; break;
                            case 2: $type = 'CHANGED'; break;
                            case 4: $type = 'REMOVED'; break;
                        }
                        fwrite(STDOUT, '['.$event->getResource()->getFilename().']['.$type.']'.PHP_EOL);
                    }
                    fwrite(STDOUT, PHP_EOL);

                    break;
                }

Normal case

[SampleTest.php][CHANGED]

PHPUnit 4.8.16 by Sebastian Bergmann and contributors.

..

Sample
 [x] Compare int
 [x] Compare string

Time: 259 ms, Memory: 8.25Mb

OK (2 tests, 2 assertions)

Case that tests run 2 times

[SampleTest.php][REMOVED]

PHPUnit 4.8.16 by Sebastian Bergmann and contributors.

..

Sample
 [x] Compare int
 [x] Compare string

Time: 303 ms, Memory: 8.25Mb

OK (2 tests, 2 assertions)

[SampleTest.php][CREATED]

PHPUnit 4.8.16 by Sebastian Bergmann and contributors.

..

Sample
 [x] Compare int
 [x] Compare string

Time: 260 ms, Memory: 8.25Mb

OK (2 tests, 2 assertions)

It seems that testrunner detects that the file is removed once and created again.

P.S.

I think, this behavior is related to vim's file saving process.

iteman commented 8 years ago

This is not a bug. See https://twitter.com/smori1983/status/658618197671723008 (Japanese)