Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/test/lib/regexr.rb
Views: 11766
## This class consists of helper methods for regexing logs1##2## TODO - clean up the style. looks like it was written in the early 90s3##4## $Id$56class Regexr78def initialize(verbose = false, case_insensitive = true)9@verbose = verbose10@case_insensitive = case_insensitive11end1213# Check for the beginning and end lines. Handy when you need to ensure a log has started & completed14def verify_start_and_end(data, the_start, the_end)15return false unless data1617data_lines = data.split("\n")18regex_start = Regexp.new(the_start, @case_insensitive)19regex_end = Regexp.new(the_end, @case_insensitive)2021if regex_start =~ data_lines.first22return regex_end =~ data_lines.last23end2425return false26end2728# Scan for any number of success lines. In order to pass, all successes must match.29def find_strings_that_dont_exist_in_data(data, regexes = [])30return false unless data3132data_lines = data.split("\n")3334return nil unless regexes ## count as a pass3536if regexes37target_successes = regexes.size38success_count = 039regexes.each { |condition|40## assume we haven't got it41found = false4243re = Regexp.new(condition, @case_insensitive)4445## for each of our data lines46data_lines.each { |line|47## if it's a match48if line =~ re49found = true50break ## success!51end52}5354if !found55return condition ## return this string, it wasn't found.56end57}58end5960nil ## got all successes, woot!61end6263# Scan for failures -- if any single failure matches, the test returns true.64def find_strings_that_exist_in_data_except(data, regexes = [], exceptions = [])65return false unless data6667data_lines = data.split("\n")6869return nil unless regexes ## count as a pass7071regexes.each { |condition|72## for each failure condition that we've been passed73re = Regexp.new(condition, @case_insensitive)7475## assume we're okay76found = false7778data_lines.each { |line|79if re =~ line80found = true # oh, we found a match8182# but let's check the exceptions83exceptions.map { |exception|84reg_exception = Regexp.new(exception, @case_insensitive)8586# If the exception matches here, we'll spare it87if reg_exception =~ line88found = false89break90end91}9293# If we didn't find an exception, we have to fail it. do not pass go.94return condition if found95end96}97}9899nil ## no failures found!100end101end102103104