fgrehm-autotestforphp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +2 -0
- data/License.txt +20 -0
- data/Manifest.txt +29 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +123 -0
- data/Rakefile +35 -0
- data/autotestforphp.gemspec +35 -0
- data/bin/autotestforphp +10 -0
- data/images/fail.png +0 -0
- data/images/pass.png +0 -0
- data/lib/autotestforphp.rb +189 -0
- data/lib/autotestforphp/cli.rb +43 -0
- data/lib/autotestforphp/notification.rb +38 -0
- data/lib/autotestforphp/notification/linux.rb +42 -0
- data/lib/autotestforphp/notification/mac.rb +16 -0
- data/lib/autotestforphp/notification/windows.rb +13 -0
- data/lib/autotestforphp/result.rb +42 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/autotestforphp/test_autotestforphp.rb +60 -0
- data/test/cli/test_autotestforphp_cli.rb +34 -0
- data/test/cli/test_install_cli.rb +33 -0
- data/test/test_helper.rb +13 -0
- data/test/test_linux.rb +63 -0
- data/test/test_mac.rb +14 -0
- data/test/test_notification.rb +35 -0
- data/test/test_result.rb +72 -0
- data/test/test_windows.rb +11 -0
- metadata +104 -0
data/History.txt
ADDED
data/License.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Fábio Rehm
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
History.txt
|
|
2
|
+
License.txt
|
|
3
|
+
Manifest.txt
|
|
4
|
+
PostInstall.txt
|
|
5
|
+
README.rdoc
|
|
6
|
+
Rakefile
|
|
7
|
+
autotestforphp.gemspec
|
|
8
|
+
bin/autotestforphp
|
|
9
|
+
images/fail.png
|
|
10
|
+
images/pass.png
|
|
11
|
+
lib/autotestforphp.rb
|
|
12
|
+
lib/autotestforphp/cli.rb
|
|
13
|
+
lib/autotestforphp/notification.rb
|
|
14
|
+
lib/autotestforphp/notification/linux.rb
|
|
15
|
+
lib/autotestforphp/notification/mac.rb
|
|
16
|
+
lib/autotestforphp/notification/windows.rb
|
|
17
|
+
lib/autotestforphp/result.rb
|
|
18
|
+
script/console
|
|
19
|
+
script/destroy
|
|
20
|
+
script/generate
|
|
21
|
+
test/autotestforphp/test_autotestforphp.rb
|
|
22
|
+
test/cli/test_autotestforphp_cli.rb
|
|
23
|
+
test/cli/test_install_cli.rb
|
|
24
|
+
test/test_helper.rb
|
|
25
|
+
test/test_linux.rb
|
|
26
|
+
test/test_mac.rb
|
|
27
|
+
test/test_notification.rb
|
|
28
|
+
test/test_result.rb
|
|
29
|
+
test/test_windows.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
= AutotestForPHP
|
|
2
|
+
|
|
3
|
+
* http://github.com/fgrehm/autotestforphp
|
|
4
|
+
* fgrehm@gmail.com
|
|
5
|
+
|
|
6
|
+
== DESCRIPTION:
|
|
7
|
+
|
|
8
|
+
AutotestForPHP is based off of ZenTest autotest which is a popular Ruby tool for running tests as soon as files get changed:
|
|
9
|
+
* http://www.zenspider.com/ZSS/Products/ZenTest/
|
|
10
|
+
|
|
11
|
+
The code for displaying notifications is based on Carlos Brando autotest-notification gem:
|
|
12
|
+
* http://github.com/carlosbrando/autotest-notification
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
== SYNOPSYS
|
|
16
|
+
|
|
17
|
+
autotestforphp --install
|
|
18
|
+
|
|
19
|
+
autotestforphp
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
== REQUIREMENTS:
|
|
23
|
+
|
|
24
|
+
* Ruby
|
|
25
|
+
* RubyGems
|
|
26
|
+
* PHP5
|
|
27
|
+
* PHPUnit
|
|
28
|
+
|
|
29
|
+
* Mac: *(NOT TESTED)*
|
|
30
|
+
You need to have Growl and growlnotify installed on your machine.
|
|
31
|
+
|
|
32
|
+
Download the Growl [http://growl.info/index.php] and install it like any other application on your Mac
|
|
33
|
+
|
|
34
|
+
Then you must install the growlnotify.
|
|
35
|
+
|
|
36
|
+
In your shell, cd to the directory on the Growl disk image containing growlnotify, and type ./install.sh.
|
|
37
|
+
That script will install growlnotify to /usr/local/bin and the manpage to /usr/local/man.
|
|
38
|
+
|
|
39
|
+
* Windows: *(NOT TESTED)*
|
|
40
|
+
You need to have Snarl and ruby-snarl installed on your machine.
|
|
41
|
+
|
|
42
|
+
Download Snarl [http://www.fullphat.net/] and install it like any other application on your machine.
|
|
43
|
+
|
|
44
|
+
Run in the command prompt:
|
|
45
|
+
|
|
46
|
+
$ gem install ruby-snarl
|
|
47
|
+
|
|
48
|
+
* Linux: *(TESTED ON KDE ONLY)*
|
|
49
|
+
You need to have libnotify binaries installed.
|
|
50
|
+
|
|
51
|
+
For ubuntu this means: sudo apt-get install libnotify-bin
|
|
52
|
+
|
|
53
|
+
Other distributions may package it with other names, do a search for libnotify using your distribution package
|
|
54
|
+
manager.
|
|
55
|
+
|
|
56
|
+
If you use KDE and do not have libnotify-bin installed, it will try to use kdialog which is part of KDE.
|
|
57
|
+
It also works if you have zenity installed.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
== INSTALL:
|
|
61
|
+
|
|
62
|
+
* gem install autotestforphp --source=http://gems.github.com
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
== SETUP
|
|
66
|
+
|
|
67
|
+
During instalation, AutotestForPHP will create:
|
|
68
|
+
* An empty PHPUnit boostrap file on 'test/bootstrap-autotest.php' to be used when running tests
|
|
69
|
+
* An empty config file on 'autotestforphp/config.autotest'
|
|
70
|
+
* A PHPUnit config file on 'test/phpunit-autotest.xml' to will configure the bootstrap file to be used, tests folder and log results to a XML file needed for displaying notifications:
|
|
71
|
+
<phpunit bootstrap="./test/bootstrap-autotest.php">
|
|
72
|
+
<testsuite name="Application">
|
|
73
|
+
<directory>./test/</directory>
|
|
74
|
+
</testsuite>
|
|
75
|
+
<logging>
|
|
76
|
+
<log type="test-xml" target="./autotestforphp/logfile.xml" />
|
|
77
|
+
</logging>
|
|
78
|
+
</phpunit>
|
|
79
|
+
|
|
80
|
+
You can specify the folders / files to be watched on 'autotestforphp/config.autotest' file by setting the FOLDERS_TO_WATCH Ruby constant:
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
FOLDERS_TO_WATCH = ['./src/**/*', './app/**/*', './test/**/*', './some_specific_file.php']
|
|
84
|
+
|
|
85
|
+
If no folders are specified on 'autotestforphp/config.autotest', AutotestForPHP will watch for changes on the following folders:
|
|
86
|
+
* src
|
|
87
|
+
* app
|
|
88
|
+
* lib
|
|
89
|
+
* test
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
== TODO:
|
|
93
|
+
|
|
94
|
+
* Skip files to be watched
|
|
95
|
+
* Check if tool was already skip file creation
|
|
96
|
+
* Test on Mac and XP
|
|
97
|
+
* Like ZenTest autotest, focus on running previous failures until they are fixed instead of running all tests all the time
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
== LICENSE:
|
|
101
|
+
|
|
102
|
+
(The MIT License)
|
|
103
|
+
|
|
104
|
+
Copyright (c) 2009 Fábio Galvão Rehm
|
|
105
|
+
|
|
106
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
107
|
+
a copy of this software and associated documentation files (the
|
|
108
|
+
'Software'), to deal in the Software without restriction, including
|
|
109
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
110
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
111
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
112
|
+
the following conditions:
|
|
113
|
+
|
|
114
|
+
The above copyright notice and this permission notice shall be
|
|
115
|
+
included in all copies or substantial portions of the Software.
|
|
116
|
+
|
|
117
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
118
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
119
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
120
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
121
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
122
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
123
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
|
3
|
+
require 'hoe'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require './lib/autotestforphp'
|
|
6
|
+
|
|
7
|
+
Hoe.plugin :newgem
|
|
8
|
+
# Hoe.plugin :website
|
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
|
10
|
+
|
|
11
|
+
# Generate all the Rake tasks
|
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
13
|
+
$hoe = Hoe.spec 'autotestforphp' do
|
|
14
|
+
self.developer 'Fábio Rehm', 'fgrehm@gmail.com'
|
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
remove_task :test
|
|
22
|
+
|
|
23
|
+
Rake::TestTask.new do |t|
|
|
24
|
+
t.libs << "lib"
|
|
25
|
+
t.test_files = FileList['test/**/test*.rb']
|
|
26
|
+
t.verbose = true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
require 'newgem/tasks'
|
|
31
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
|
32
|
+
|
|
33
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
|
34
|
+
# remove_task :default
|
|
35
|
+
# task :default => [:spec, :features]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = %q{autotestforphp}
|
|
3
|
+
s.version = "0.0.1"
|
|
4
|
+
|
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
|
+
s.authors = ["F\303\241bio Rehm"]
|
|
7
|
+
s.date = %q{2009-07-24}
|
|
8
|
+
s.default_executable = %q{autotestforphp}
|
|
9
|
+
s.description = %q{Autotest tool for PHP}
|
|
10
|
+
s.email = ["fgrehm@gmail.com"]
|
|
11
|
+
s.executables = ["autotestforphp"]
|
|
12
|
+
s.homepage = %q{http://github.com/fgrehm/autotestforphp}
|
|
13
|
+
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
|
14
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "autotestforphp.gemspec", "bin/autotestforphp", "images/fail.png", "images/pass.png", "lib/autotestforphp.rb", "lib/autotestforphp/cli.rb", "lib/autotestforphp/notification.rb", "lib/autotestforphp/notification/linux.rb", "lib/autotestforphp/notification/mac.rb", "lib/autotestforphp/notification/windows.rb", "lib/autotestforphp/result.rb", "script/console", "script/destroy", "script/generate", "test/autotestforphp/test_autotestforphp.rb", "test/cli/test_autotestforphp_cli.rb", "test/cli/test_install_cli.rb", "test/test_helper.rb", "test/test_linux.rb", "test/test_mac.rb", "test/test_notification.rb", "test/test_result.rb", "test/test_windows.rb"]
|
|
15
|
+
s.post_install_message = %q{PostInstall.txt}
|
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
s.rubyforge_project = %q{autotestforphp}
|
|
19
|
+
s.rubygems_version = %q{1.3.4}
|
|
20
|
+
s.summary = %q{Autotest tool for PHP}
|
|
21
|
+
s.test_files = ["test/cli/test_autotestforphp_cli.rb", "test/cli/test_install_cli.rb", "test/test_linux.rb", "test/test_notification.rb", "test/test_helper.rb", "test/test_windows.rb", "test/test_result.rb", "test/test_mac.rb", "test/autotestforphp/test_autotestforphp.rb"]
|
|
22
|
+
|
|
23
|
+
if s.respond_to? :specification_version then
|
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
25
|
+
s.specification_version = 3
|
|
26
|
+
|
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
28
|
+
s.add_development_dependency(%q<hoe>, [">= 2.3.2"])
|
|
29
|
+
else
|
|
30
|
+
s.add_dependency(%q<hoe>, [">= 2.3.2"])
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
s.add_dependency(%q<hoe>, [">= 2.3.2"])
|
|
34
|
+
end
|
|
35
|
+
end
|
data/bin/autotestforphp
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# Created on 2009-7-22.
|
|
4
|
+
# Copyright (c) 2009. All rights reserved.
|
|
5
|
+
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/autotestforphp")
|
|
8
|
+
require "autotestforphp/cli"
|
|
9
|
+
|
|
10
|
+
Autotestforphp::CLI.execute(STDOUT, ARGV)
|
data/images/fail.png
ADDED
|
Binary file
|
data/images/pass.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
|
+
|
|
4
|
+
require 'date'
|
|
5
|
+
require 'rexml/document'
|
|
6
|
+
require 'autotestforphp/notification'
|
|
7
|
+
require 'autotestforphp/result'
|
|
8
|
+
|
|
9
|
+
class Autotestforphp
|
|
10
|
+
VERSION = '0.0.1'
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def install
|
|
14
|
+
new.install
|
|
15
|
+
end
|
|
16
|
+
def run(folders_to_watch)
|
|
17
|
+
folders_to_watch.map!{ |folder| File.expand_path(folder) }
|
|
18
|
+
atp = new
|
|
19
|
+
atp.watch(folders_to_watch)
|
|
20
|
+
atp.run
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_accessor(:files_to_watch,
|
|
25
|
+
:filters,
|
|
26
|
+
:interrupted,
|
|
27
|
+
:last_mtime,
|
|
28
|
+
:tainted,
|
|
29
|
+
:wants_to_quit)
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
# reset
|
|
33
|
+
self.files_to_watch = []
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def base_path=(path)
|
|
37
|
+
@@base_path = path
|
|
38
|
+
end
|
|
39
|
+
def base_path
|
|
40
|
+
if not defined? @@base_path
|
|
41
|
+
self.base_path = File.expand_path('./') + "/"
|
|
42
|
+
end
|
|
43
|
+
@@base_path
|
|
44
|
+
end
|
|
45
|
+
def config_file_path
|
|
46
|
+
"#{base_path}autotestforphp/config.autotest"
|
|
47
|
+
end
|
|
48
|
+
def phpunit_log_file_path
|
|
49
|
+
"#{base_path}autotestforphp/logfile.xml"
|
|
50
|
+
end
|
|
51
|
+
def phpunit_config_file_path
|
|
52
|
+
"#{base_path}test/phpunit-autotest.xml"
|
|
53
|
+
end
|
|
54
|
+
def bootstrap_file_path
|
|
55
|
+
"#{base_path}test/bootstrap.php"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def phpunit_config_file_exists?
|
|
59
|
+
File.exist?(phpunit_config_file_path)
|
|
60
|
+
end
|
|
61
|
+
def bootstrap_file_exists?
|
|
62
|
+
File.exist?(bootstrap_file_path)
|
|
63
|
+
end
|
|
64
|
+
def phpunit_log_file_exists?
|
|
65
|
+
File.exist?(phpunit_log_file_path)
|
|
66
|
+
end
|
|
67
|
+
def config_file_exists?
|
|
68
|
+
File.exist?(config_file_path)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def make_test_cmd
|
|
72
|
+
case RUBY_PLATFORM
|
|
73
|
+
when /linux/
|
|
74
|
+
cmd = "phpunit"
|
|
75
|
+
when /mswin/
|
|
76
|
+
cmd = "phpunit.bat"
|
|
77
|
+
else
|
|
78
|
+
raise('Your OS not supported yet!')
|
|
79
|
+
end
|
|
80
|
+
"#{cmd} --configuration \"#{phpunit_config_file_path}\""
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def install
|
|
84
|
+
File.open(phpunit_config_file_path, 'w') do |f|
|
|
85
|
+
f.puts <<-CONFIG
|
|
86
|
+
<phpunit bootstrap="./test/bootstrap-autotest.php">
|
|
87
|
+
<testsuite name="Application">
|
|
88
|
+
<directory>./test/</directory>
|
|
89
|
+
</testsuite>
|
|
90
|
+
<logging>
|
|
91
|
+
<log type="test-xml" target="./autotestforphp/logfile.xml" />
|
|
92
|
+
</logging>
|
|
93
|
+
</phpunit>
|
|
94
|
+
CONFIG
|
|
95
|
+
end
|
|
96
|
+
File.open(bootstrap_file_path, 'w').close
|
|
97
|
+
Dir.mkdir("#{base_path}autotestforphp/") unless File.exist?("#{base_path}autotestforphp/")
|
|
98
|
+
File.open(config_file_path, 'w').close
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def run
|
|
102
|
+
add_sigint_handler
|
|
103
|
+
|
|
104
|
+
loop do # ^c handler
|
|
105
|
+
begin
|
|
106
|
+
run_all_tests
|
|
107
|
+
wait_for_changes
|
|
108
|
+
rescue Interrupt
|
|
109
|
+
break if self.wants_to_quit
|
|
110
|
+
reset
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def run_all_tests
|
|
116
|
+
cmd = make_test_cmd
|
|
117
|
+
self.last_mtime = Time.now
|
|
118
|
+
|
|
119
|
+
clear_log
|
|
120
|
+
clear_screen
|
|
121
|
+
puts cmd
|
|
122
|
+
system(cmd)
|
|
123
|
+
|
|
124
|
+
notify
|
|
125
|
+
end
|
|
126
|
+
def watch(folders)
|
|
127
|
+
self.last_mtime = Time.now
|
|
128
|
+
self.filters = folders
|
|
129
|
+
folders.each do |arg|
|
|
130
|
+
Dir[arg].each do |file|
|
|
131
|
+
self.files_to_watch << file unless File.directory?(file)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
def files_have_changed
|
|
136
|
+
not self.files_to_watch.find { |f|
|
|
137
|
+
File.exist?(f) and File.mtime(f) > self.last_mtime
|
|
138
|
+
}.nil?
|
|
139
|
+
end
|
|
140
|
+
def add_sigint_handler
|
|
141
|
+
trap 'INT' do
|
|
142
|
+
if self.interrupted then
|
|
143
|
+
self.wants_to_quit = true
|
|
144
|
+
else
|
|
145
|
+
puts "Interrupt a second time to quit"
|
|
146
|
+
self.interrupted = true
|
|
147
|
+
sleep 1.5
|
|
148
|
+
raise Interrupt, nil # let the run loop catch it
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
def wait_for_changes
|
|
153
|
+
sleep 1.5 until files_have_changed
|
|
154
|
+
end
|
|
155
|
+
def reset
|
|
156
|
+
self.interrupted = false
|
|
157
|
+
self.tainted = false
|
|
158
|
+
self.wants_to_quit = false
|
|
159
|
+
self.watch(self.filters)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
def clear_log
|
|
165
|
+
File.delete(phpunit_log_file_path) if phpunit_log_file_exists?
|
|
166
|
+
end
|
|
167
|
+
def clear_screen
|
|
168
|
+
case RUBY_PLATFORM
|
|
169
|
+
when /linux/
|
|
170
|
+
system("clear")
|
|
171
|
+
when /mswin/
|
|
172
|
+
system("cls")
|
|
173
|
+
else
|
|
174
|
+
raise('Your OS not supported yet!')
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
def notify
|
|
178
|
+
unless File.exist?(phpunit_log_file_path) and File.size(phpunit_log_file_path) > 0
|
|
179
|
+
msg = 'Tests could not be executed'
|
|
180
|
+
img = Notification::Config.fail_image
|
|
181
|
+
else
|
|
182
|
+
result = Result.build_from_xml(File.new(phpunit_log_file_path))
|
|
183
|
+
msg = result.message
|
|
184
|
+
img = result.image
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
Notification.notify('Autotest for PHP', msg, img)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
class Autotestforphp
|
|
4
|
+
class CLI
|
|
5
|
+
def self.execute(stdout, arguments=['--run'])
|
|
6
|
+
arguments = ['--run'] unless arguments.count > 0 # defaults to run
|
|
7
|
+
|
|
8
|
+
OptionParser.new do |opts|
|
|
9
|
+
opts.banner = <<-BANNER.gsub(/^ /,'')
|
|
10
|
+
Usage: #{File.basename($0)} [options]
|
|
11
|
+
|
|
12
|
+
Options are:
|
|
13
|
+
BANNER
|
|
14
|
+
|
|
15
|
+
opts.separator("")
|
|
16
|
+
|
|
17
|
+
opts.on('-i', '--install',
|
|
18
|
+
'Install AutotestForPHP') do
|
|
19
|
+
Autotestforphp.install
|
|
20
|
+
stdout.puts 'Autotest for PHP was installed successfully'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on('-r', '--run',
|
|
24
|
+
'Run AutotestForPHP (default)') do
|
|
25
|
+
config_file = File.expand_path('./autotestforphp/config.autotest')
|
|
26
|
+
load config_file if File.exist?(config_file)
|
|
27
|
+
|
|
28
|
+
unless defined?(FOLDERS_TO_WATCH)
|
|
29
|
+
folders = ["./src/**/*", "./test/**/*", "./app/**/*", "./lib/**/*"]
|
|
30
|
+
else
|
|
31
|
+
folders = FOLDERS_TO_WATCH
|
|
32
|
+
end
|
|
33
|
+
Autotestforphp.run(folders)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
opts.on("-h", "--help",
|
|
37
|
+
"Show this help message.") { stdout.puts opts; exit }
|
|
38
|
+
|
|
39
|
+
opts.parse!(arguments)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Autotestforphp
|
|
2
|
+
module Notification
|
|
3
|
+
class Config
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
attr_reader :images_directory
|
|
7
|
+
attr_accessor :success_image, :fail_image#, :expiration_in_seconds
|
|
8
|
+
|
|
9
|
+
def images_directory=(path)
|
|
10
|
+
@images_directory = File.expand_path(path)
|
|
11
|
+
|
|
12
|
+
@success_image = "#{@images_directory}/pass.png"
|
|
13
|
+
@fail_image = "#{@images_directory}/fail.png"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
self.images_directory = "#{File.dirname(__FILE__)}/../../images/"
|
|
18
|
+
|
|
19
|
+
# self.expiration_in_seconds = 3
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
def notify(title, msg, img = Config.success_image)
|
|
25
|
+
case RUBY_PLATFORM
|
|
26
|
+
when /linux/
|
|
27
|
+
Linux.notify(title, msg, img)
|
|
28
|
+
when /darwin/
|
|
29
|
+
Mac.notify(title, msg, img)
|
|
30
|
+
when /mswin/
|
|
31
|
+
Windows.notify(title, msg, img)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
%w{ linux mac windows }.each { |x| require "autotestforphp/notification/#{x}" }
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class Autotestforphp
|
|
2
|
+
module Notification
|
|
3
|
+
module Linux
|
|
4
|
+
class << self
|
|
5
|
+
|
|
6
|
+
def notify(title, msg, img)
|
|
7
|
+
if has_notify?
|
|
8
|
+
notify_send(title, msg, img)
|
|
9
|
+
elsif has_zenity?
|
|
10
|
+
zenity(title, msg, img)
|
|
11
|
+
elsif has_kdialog?
|
|
12
|
+
kdialog(title, msg, img)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def has_notify?
|
|
17
|
+
system "which notify-send > /dev/null 2>&1"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def has_kdialog?
|
|
21
|
+
system "which kdialog > /dev/null 2>&1"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def has_zenity?
|
|
25
|
+
system "which zenity > /dev/null 2>&1"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def notify_send(title, msg, img)
|
|
29
|
+
system "notify-send -i #{img} '#{title}' '#{msg}'"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def kdialog(title, msg, img)
|
|
33
|
+
system "kdialog --title '#{title}' --passivepopup '<img src=\"#{img}\" align=\"middle\"> #{msg}'"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def zenity(title, msg, img)
|
|
37
|
+
system "zenity --info --text='#{msg}' --title='#{title}'"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'snarl' if RUBY_PLATFORM =~ /mswin/
|
|
2
|
+
|
|
3
|
+
class Autotestforphp
|
|
4
|
+
module Notification
|
|
5
|
+
module Mac
|
|
6
|
+
@last_test_failed = false
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
|
|
10
|
+
def notify(title, msg, img)
|
|
11
|
+
system "growlnotify -n autotest --image #{img} -m '#{msg}' -t #{title}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class Autotestforphp
|
|
2
|
+
class Result
|
|
3
|
+
include REXML
|
|
4
|
+
|
|
5
|
+
attr_reader(:num_tests,
|
|
6
|
+
:num_assertions,
|
|
7
|
+
:num_errors,
|
|
8
|
+
:num_failures)
|
|
9
|
+
|
|
10
|
+
def initialize(num_tests, num_assertions, num_errors, num_failures)
|
|
11
|
+
@num_tests = num_tests
|
|
12
|
+
@num_assertions = num_assertions
|
|
13
|
+
@num_errors = num_errors
|
|
14
|
+
@num_failures = num_failures
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def message
|
|
18
|
+
"#{num_tests} tests, #{num_assertions} assertions, #{num_failures} failures, #{num_errors} errors"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def image
|
|
22
|
+
config = Autotestforphp::Notification::Config
|
|
23
|
+
if num_failures == 0 and num_errors == 0
|
|
24
|
+
config.success_image
|
|
25
|
+
else
|
|
26
|
+
config.fail_image
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.build_from_xml(xml)
|
|
31
|
+
unless xml.is_a?(Document)
|
|
32
|
+
xml = Document.new(xml)
|
|
33
|
+
end
|
|
34
|
+
results = XPath.first(xml, '//testsuite')
|
|
35
|
+
num_tests = results.attributes["tests"].to_i
|
|
36
|
+
num_failures = results.attributes["failures"].to_i
|
|
37
|
+
num_errors = results.attributes["errors"].to_i
|
|
38
|
+
num_assertions = results.attributes["assertions"].to_i
|
|
39
|
+
new(num_tests, num_assertions, num_errors, num_failures)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/script/console
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# File: script/console
|
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
4
|
+
|
|
5
|
+
libs = " -r irb/completion"
|
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/autotestforphp.rb'}"
|
|
9
|
+
puts "Loading autotestforphp gem"
|
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'rubigen'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'rubigen'
|
|
9
|
+
end
|
|
10
|
+
require 'rubigen/scripts/destroy'
|
|
11
|
+
|
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'rubigen'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'rubigen'
|
|
9
|
+
end
|
|
10
|
+
require 'rubigen/scripts/generate'
|
|
11
|
+
|
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
|
2
|
+
|
|
3
|
+
# NOT TESTED:
|
|
4
|
+
# add_sigint_handler
|
|
5
|
+
# notify
|
|
6
|
+
# reset
|
|
7
|
+
# run
|
|
8
|
+
|
|
9
|
+
class TestAutotestforphp < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
@atp = Autotestforphp.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def teardown
|
|
16
|
+
File.delete(File.dirname(__FILE__) + '/sample.php') if File.exist?(File.dirname(__FILE__) + '/sample.php')
|
|
17
|
+
File.delete(File.dirname(__FILE__) + '/sample2.php') if File.exist?(File.dirname(__FILE__) + '/sample2.php')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_detect_file_change
|
|
21
|
+
create_file('sample.php')
|
|
22
|
+
create_file('sample2.php')
|
|
23
|
+
|
|
24
|
+
@atp.watch(File.dirname(__FILE__) + '/sample*')
|
|
25
|
+
assert !@atp.files_have_changed
|
|
26
|
+
|
|
27
|
+
sleep 1
|
|
28
|
+
touch_file('sample2.php')
|
|
29
|
+
|
|
30
|
+
assert @atp.files_have_changed
|
|
31
|
+
@atp.last_mtime = Time.now
|
|
32
|
+
|
|
33
|
+
sleep 1
|
|
34
|
+
assert !@atp.files_have_changed
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_make_test_cmd_linux
|
|
38
|
+
@atp.class.const_set :RUBY_PLATFORM, 'linux'
|
|
39
|
+
assert_equal "phpunit --configuration \"#{@atp.phpunit_config_file_path}\"", @atp.make_test_cmd
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_make_test_cmd_windows
|
|
43
|
+
@atp.class.const_set :RUBY_PLATFORM, 'mswin'
|
|
44
|
+
assert_equal "phpunit.bat --configuration \"#{@atp.phpunit_config_file_path}\"", @atp.make_test_cmd
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# def test_make_test_cmd_mac
|
|
48
|
+
#
|
|
49
|
+
# end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
def create_file(file_name)
|
|
53
|
+
File.new("#{File.dirname(__FILE__)}/#{file_name}", 'w').close
|
|
54
|
+
end
|
|
55
|
+
def touch_file(file_name)
|
|
56
|
+
File.open("#{File.dirname(__FILE__)}/#{file_name}", 'w') do |f|
|
|
57
|
+
f.puts 'test'
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', "test_helper.rb")
|
|
2
|
+
require 'autotestforphp/cli'
|
|
3
|
+
require 'mocha'
|
|
4
|
+
|
|
5
|
+
class TestAutotestforphpCli < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@atp = Autotestforphp
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_default_folders_to_watch
|
|
11
|
+
@atp.expects(:run).
|
|
12
|
+
with(["./src/**/*", "./test/**/*", "./app/**/*", "./lib/**/*"]).
|
|
13
|
+
once
|
|
14
|
+
|
|
15
|
+
execute
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_loads_folders_from_config
|
|
19
|
+
@atp.const_set :FOLDERS_TO_WATCH, ["./src/**/*"]
|
|
20
|
+
@atp.expects(:run).
|
|
21
|
+
with(["./src/**/*"]).
|
|
22
|
+
once
|
|
23
|
+
|
|
24
|
+
execute
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def execute
|
|
30
|
+
Autotestforphp::CLI.execute(@stdout_io = StringIO.new)
|
|
31
|
+
@stdout_io.rewind
|
|
32
|
+
@stdout = @stdout_io.read
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', "test_helper.rb")
|
|
2
|
+
require 'autotestforphp/cli'
|
|
3
|
+
|
|
4
|
+
class TestInstallCli < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
@atp = Autotestforphp.new
|
|
7
|
+
@atp.base_path = File.dirname(__FILE__) + '/'
|
|
8
|
+
|
|
9
|
+
Dir.mkdir("#{@atp.base_path}test/") unless File.exist?("#{@atp.base_path}test/")
|
|
10
|
+
|
|
11
|
+
Autotestforphp::CLI.execute(@stdout_io = StringIO.new, ['--install'])
|
|
12
|
+
@stdout_io.rewind
|
|
13
|
+
@stdout = @stdout_io.read
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def teardown
|
|
17
|
+
File.delete(@atp.bootstrap_file_path) if File.exist?(@atp.bootstrap_file_path)
|
|
18
|
+
File.delete(@atp.phpunit_config_file_path) if File.exist?(@atp.phpunit_config_file_path)
|
|
19
|
+
File.delete(@atp.config_file_path) if File.exist?(@atp.config_file_path)
|
|
20
|
+
Dir.delete("#{@atp.base_path}autotestforphp/") if File.exist?("#{@atp.base_path}autotestforphp/")
|
|
21
|
+
Dir.delete("#{@atp.base_path}test/") if File.exist?("#{@atp.base_path}test/")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_print_default_output
|
|
25
|
+
assert_match(/Autotest for PHP was installed successfully/, @stdout)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_create_files
|
|
29
|
+
assert @atp.phpunit_config_file_exists?
|
|
30
|
+
assert @atp.bootstrap_file_exists?
|
|
31
|
+
assert @atp.config_file_exists?
|
|
32
|
+
end
|
|
33
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_linux.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestLinux < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@notifier = Autotestforphp::Notification::Linux
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_notify_when_use_notify
|
|
10
|
+
@notifier.expects(:has_notify?).returns(true)
|
|
11
|
+
verify_notify(:notify_send)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_notify_when_use_zenity
|
|
15
|
+
@notifier.expects(:has_notify?).returns(false)
|
|
16
|
+
@notifier.expects(:has_zenity?).returns(true)
|
|
17
|
+
verify_notify(:zenity)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_notify_when_use_kdialog
|
|
21
|
+
@notifier.expects(:has_notify?).returns(false)
|
|
22
|
+
@notifier.expects(:has_zenity?).returns(false)
|
|
23
|
+
@notifier.expects(:has_kdialog?).returns(true)
|
|
24
|
+
verify_notify(:kdialog)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_notify_send
|
|
28
|
+
@notifier.expects(:system).with('notify-send -i image \'title\' \'msg\'')
|
|
29
|
+
@notifier.notify_send("title", "msg", "image")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_notify_kdialog
|
|
33
|
+
@notifier.expects(:system).with('kdialog --title \'title\' --passivepopup \'<img src="image" align="middle"> msg\'')
|
|
34
|
+
@notifier.kdialog("title", "msg", "image")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_notify_zenity
|
|
38
|
+
@notifier.expects(:system).with('zenity --info --text=\'msg\' --title=\'title\'')
|
|
39
|
+
@notifier.zenity("title", "msg", "image")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_has_zenity?
|
|
43
|
+
@notifier.expects(:system).with('which zenity > /dev/null 2>&1')
|
|
44
|
+
@notifier.has_zenity?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_has_notify?
|
|
48
|
+
@notifier.expects(:system).with('which notify-send > /dev/null 2>&1')
|
|
49
|
+
@notifier.has_notify?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_has_kdialog?
|
|
53
|
+
@notifier.expects(:system).with('which kdialog > /dev/null 2>&1')
|
|
54
|
+
@notifier.has_kdialog?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def verify_notify(method)
|
|
60
|
+
@notifier.expects(method).returns("title", "msg", "image")
|
|
61
|
+
@notifier.notify("title", "msg", "image")
|
|
62
|
+
end
|
|
63
|
+
end
|
data/test/test_mac.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestMac < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@notifier = Autotestforphp::Notification::Mac
|
|
7
|
+
@notifier.stubs(:system)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_notify
|
|
11
|
+
@notifier.expects(:system).with("growlnotify -n autotest --image image -m 'msg' -t title")
|
|
12
|
+
@notifier.notify("title", "msg", "image")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestNotification < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@title = "title"
|
|
7
|
+
@msg = "message"
|
|
8
|
+
@image = "image"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_notify_when_os_is_windows
|
|
12
|
+
notifier = Autotestforphp::Notification::Windows
|
|
13
|
+
notifier.expects(:notify).with(@title, @msg, @image)
|
|
14
|
+
verify_to("mswin")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_notify_when_os_is_linux
|
|
18
|
+
notifier = Autotestforphp::Notification::Linux
|
|
19
|
+
notifier.expects(:notify).with(@title, @msg, @image)
|
|
20
|
+
verify_to("linux")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_notify_when_os_is_mac
|
|
24
|
+
notifier = Autotestforphp::Notification::Mac
|
|
25
|
+
notifier.expects(:notify).with(@title, @msg, @image)
|
|
26
|
+
verify_to("darwin")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def verify_to(so)
|
|
32
|
+
Autotestforphp::Notification.const_set :RUBY_PLATFORM, so
|
|
33
|
+
Autotestforphp::Notification.notify(@title, @msg, @image)
|
|
34
|
+
end
|
|
35
|
+
end
|
data/test/test_result.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
class TestResult < Test::Unit::TestCase
|
|
4
|
+
include REXML
|
|
5
|
+
|
|
6
|
+
def test_can_parse_xml
|
|
7
|
+
verify_results(10, 4, 2, 1)
|
|
8
|
+
verify_results(10, 0, 0, 0)
|
|
9
|
+
verify_results(10, 2, 3, 1)
|
|
10
|
+
verify_results(100, 200, 22, 51)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_message
|
|
14
|
+
verify_message(100, 200, 1, 0)
|
|
15
|
+
verify_message(12, 22, 1, 7)
|
|
16
|
+
verify_message(13, 5, 0, 3)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_image_when_all_passed
|
|
20
|
+
result = create_result(100, 100, 0, 0)
|
|
21
|
+
|
|
22
|
+
assert_equal(Autotestforphp::Notification::Config.success_image, result.image)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_image_when_failed
|
|
26
|
+
# result = create_result(100, 100, 0, 0)
|
|
27
|
+
#
|
|
28
|
+
# assert_equal(Autotestforphp::Notification::Config.success_image)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def create_result(num_tests, num_assertions, num_errors, num_failures)
|
|
34
|
+
xml = build_xml(num_tests, num_assertions, num_errors, num_failures)
|
|
35
|
+
Autotestforphp::Result.build_from_xml(xml)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def verify_message(num_tests, num_assertions, num_errors, num_failures)
|
|
39
|
+
result = create_result(num_tests, num_assertions, num_errors, num_failures)
|
|
40
|
+
|
|
41
|
+
assert_equal("#{num_tests} tests, #{num_assertions} assertions, #{num_failures} failures, #{num_errors} errors", result.message)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def verify_results(num_tests, num_assertions, num_errors, num_failures)
|
|
45
|
+
result = create_result(num_tests, num_assertions, num_errors, num_failures)
|
|
46
|
+
|
|
47
|
+
assert_equal(num_tests, result.num_tests)
|
|
48
|
+
assert_equal(num_assertions, result.num_assertions)
|
|
49
|
+
assert_equal(num_errors, result.num_errors)
|
|
50
|
+
assert_equal(num_failures, result.num_failures)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def build_xml(num_tests, num_assertions, num_errors, num_failures)
|
|
54
|
+
<<EOF
|
|
55
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
56
|
+
<testsuites>
|
|
57
|
+
<testsuite name="FailureErrorTest" file="/home/sb/FailureErrorTest.php" tests="#{num_tests}" assertions="#{num_assertions}" failures="#{num_failures}" errors="#{num_errors}" time="0.019744">
|
|
58
|
+
<testcase name="testFailure" class="FailureErrorTest" file="/home/sb/FailureErrorTest.php" line="6" assertions="1" time="0.011456">
|
|
59
|
+
<failure type="PHPUnit_Framework_ExpectationFailedException">
|
|
60
|
+
failure description
|
|
61
|
+
</failure>
|
|
62
|
+
</testcase>
|
|
63
|
+
<testcase name="testError" class="FailureErrorTest" file="/home/sb/FailureErrorTest.php" line="11" assertions="0" time="0.008288">
|
|
64
|
+
<error type="Exception">testError(FailureErrorTest)
|
|
65
|
+
exception description
|
|
66
|
+
</error>
|
|
67
|
+
</testcase>
|
|
68
|
+
</testsuite>
|
|
69
|
+
</testsuites>
|
|
70
|
+
EOF
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
class Snarl
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class TestWindows < Test::Unit::TestCase
|
|
7
|
+
def test_notify
|
|
8
|
+
Snarl.expects(:show_message).with("title", "msg", "image")
|
|
9
|
+
Autotestforphp::Notification::Windows.notify("title", "msg", "image")
|
|
10
|
+
end
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fgrehm-autotestforphp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "F\xC3\xA1bio Rehm"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-07-24 00:00:00 -07:00
|
|
13
|
+
default_executable: autotestforphp
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: hoe
|
|
17
|
+
type: :development
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 2.3.2
|
|
24
|
+
version:
|
|
25
|
+
description: Autotest tool for PHP
|
|
26
|
+
email:
|
|
27
|
+
- fgrehm@gmail.com
|
|
28
|
+
executables:
|
|
29
|
+
- autotestforphp
|
|
30
|
+
extensions: []
|
|
31
|
+
|
|
32
|
+
extra_rdoc_files:
|
|
33
|
+
- History.txt
|
|
34
|
+
- License.txt
|
|
35
|
+
- Manifest.txt
|
|
36
|
+
- PostInstall.txt
|
|
37
|
+
- README.rdoc
|
|
38
|
+
files:
|
|
39
|
+
- History.txt
|
|
40
|
+
- License.txt
|
|
41
|
+
- Manifest.txt
|
|
42
|
+
- PostInstall.txt
|
|
43
|
+
- README.rdoc
|
|
44
|
+
- Rakefile
|
|
45
|
+
- autotestforphp.gemspec
|
|
46
|
+
- bin/autotestforphp
|
|
47
|
+
- images/fail.png
|
|
48
|
+
- images/pass.png
|
|
49
|
+
- lib/autotestforphp.rb
|
|
50
|
+
- lib/autotestforphp/cli.rb
|
|
51
|
+
- lib/autotestforphp/notification.rb
|
|
52
|
+
- lib/autotestforphp/notification/linux.rb
|
|
53
|
+
- lib/autotestforphp/notification/mac.rb
|
|
54
|
+
- lib/autotestforphp/notification/windows.rb
|
|
55
|
+
- lib/autotestforphp/result.rb
|
|
56
|
+
- script/console
|
|
57
|
+
- script/destroy
|
|
58
|
+
- script/generate
|
|
59
|
+
- test/autotestforphp/test_autotestforphp.rb
|
|
60
|
+
- test/cli/test_autotestforphp_cli.rb
|
|
61
|
+
- test/cli/test_install_cli.rb
|
|
62
|
+
- test/test_helper.rb
|
|
63
|
+
- test/test_linux.rb
|
|
64
|
+
- test/test_mac.rb
|
|
65
|
+
- test/test_notification.rb
|
|
66
|
+
- test/test_result.rb
|
|
67
|
+
- test/test_windows.rb
|
|
68
|
+
has_rdoc: false
|
|
69
|
+
homepage: http://github.com/fgrehm/autotestforphp
|
|
70
|
+
post_install_message: PostInstall.txt
|
|
71
|
+
rdoc_options:
|
|
72
|
+
- --main
|
|
73
|
+
- README.rdoc
|
|
74
|
+
require_paths:
|
|
75
|
+
- lib
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: "0"
|
|
81
|
+
version:
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: "0"
|
|
87
|
+
version:
|
|
88
|
+
requirements: []
|
|
89
|
+
|
|
90
|
+
rubyforge_project: autotestforphp
|
|
91
|
+
rubygems_version: 1.2.0
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 3
|
|
94
|
+
summary: Autotest tool for PHP
|
|
95
|
+
test_files:
|
|
96
|
+
- test/cli/test_autotestforphp_cli.rb
|
|
97
|
+
- test/cli/test_install_cli.rb
|
|
98
|
+
- test/test_linux.rb
|
|
99
|
+
- test/test_notification.rb
|
|
100
|
+
- test/test_helper.rb
|
|
101
|
+
- test/test_windows.rb
|
|
102
|
+
- test/test_result.rb
|
|
103
|
+
- test/test_mac.rb
|
|
104
|
+
- test/autotestforphp/test_autotestforphp.rb
|