Kouhei Sutou
null+****@clear*****
Tue Dec 17 18:17:39 JST 2013
Kouhei Sutou 2013-12-17 18:17:39 +0900 (Tue, 17 Dec 2013) New Revision: 40ebf5d5027dc3f2c19be72cbbe8679553794104 https://github.com/droonga/drntest/commit/40ebf5d5027dc3f2c19be72cbbe8679553794104 Message: Share JSON parser error report method Modified files: lib/drntest/json-loader.rb lib/drntest/test-executor.rb Modified: lib/drntest/json-loader.rb (+13 -7) =================================================================== --- lib/drntest/json-loader.rb 2013-12-17 18:15:01 +0900 (073d3e2) +++ lib/drntest/json-loader.rb 2013-12-17 18:17:39 +0900 (b095a17) @@ -17,6 +17,18 @@ require "yajl" module Drntest class JSONLoader + class << self + def report_error(path, data, error) + marker = "-" * 60 + puts("Failed to load JSONs file: #{path}") + puts(marker) + puts(data) + puts(marker) + puts(error) + puts(marker) + end + end + attr_reader :objects def initialize @@ -39,13 +51,7 @@ module Drntest begin self << line rescue Yajl::ParseError => error - marker = "-" * 60 - puts("Failed to load JSONs file: #{path}") - puts(marker) - puts(data) - puts(marker) - puts(error) - puts(marker) + self.class.report_error(path, data, error) break end end Modified: lib/drntest/test-executor.rb (+5 -4) =================================================================== --- lib/drntest/test-executor.rb 2013-12-17 18:15:01 +0900 (e1f6b8e) +++ lib/drntest/test-executor.rb 2013-12-17 18:17:39 +0900 (ac22710) @@ -13,8 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -require "yajl" - +require "drntest/json-loader" require "drntest/request-executor" module Drntest @@ -63,7 +62,9 @@ module Drntest parser.on_parse_complete = lambda do |object| objects << object end + data = "" Pathname(path).read.each_line do |line| + data << line if line[0] == "#" if Directive.directive?(line) directive = Directive.new(line) @@ -78,8 +79,8 @@ module Drntest else begin parser << line - rescue StandardError => error - p "Failed to load JSONs file: #{path.to_s}" + rescue Yajl::ParseError => error + JSONLoader.report_error(path, data, error) raise error end end -------------- next part -------------- HTML����������������������������... Download