我想要实现的是通过使用监视器来跟踪两个目录中的文件更改。
我的文件结构如下:
/PluginDir
/classes
Wrapper.php
/Tests
/classes
WrapperTest.php
autotest_watchr.rbautotest_watchr.rb的内容如下:
watch("../../classes/(.*).php") do |match|
run_test %{#{match[1]}Test.php}
end
watch(".*Test.php") do |match|
run_test match[0]
end
def run_test(file)
clear_console()
unless File.exists?(file)
puts "#{file} does not exists"
return
end
puts "Running #{file}"
results = `phpunit #{file}`
puts results
if results.match(/OK/)
notify "#{file}", "Tests Passed Successfuly", 4500
elsif results.match(/FAILURES\!/)
notify_failed file, results
end
end
def notify_failed cmd, results
failed_examples = results.scan(/([0-9]+\))\s+(.*)/)
notify "#{cmd}", failed_examples[0], 6000
end
def notify title, msg, show_time
systemMsg = "notifu.exe /p \"#{title}\" /m \"#{msg}\" /d #{show_time}"
systemMsg.gsub('“', "'")
system systemMsg
end
def clear_console
system "cls"
end然后从文件夹/PluginDir/Test/classes/我从cmd执行以下命令:
watchr autotest_watchr.rb在本例中,脚本开始正常执行,当我对Test文件进行修改时,控制台将被更新,但是当我在/PluginDir/classes/*..php文件中创建修改时,我的控制台中没有任何更新。
为什么?
注意:在first (“../../classes/.我也尝试了匹配”,以防regex变量不正确,但脚本仍然不能工作
发布于 2013-06-20 09:27:43
在您的第一个搜索字符串“././classes/(.*).php”中,我认为。字符实际上是任何单个字符的位置持有者。对于您的用法,您可能需要使用反斜杠来转义它,因此它将是:
'\.\./\.\./classes/(.*)\.php'
https://stackoverflow.com/questions/17208581
复制相似问题