Feature #12299 » 0001-Add-Warning-module-for-customized-warning-handling.patch
| error.c | ||
|---|---|---|
|
VALUE rb_eEAGAIN;
|
||
|
VALUE rb_eEWOULDBLOCK;
|
||
|
VALUE rb_eEINPROGRESS;
|
||
|
VALUE rb_mWarning;
|
||
|
static ID id_warn;
|
||
|
extern const char ruby_description[];
|
||
| ... | ... | |
|
}
|
||
|
static VALUE
|
||
|
rb_warning_s_warn(VALUE mod, VALUE str)
|
||
|
{
|
||
|
rb_write_error_str(str);
|
||
|
return Qnil;
|
||
|
}
|
||
|
static void
|
||
|
rb_write_warning_str(VALUE str)
|
||
|
{
|
||
|
rb_funcall(rb_mWarning, id_warn, 1, str);
|
||
|
}
|
||
|
static VALUE
|
||
|
warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
|
||
|
{
|
||
|
VALUE str = rb_enc_str_new(0, 0, enc);
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
str = warn_vsprintf(NULL, file, line, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(str);
|
||
|
rb_write_warning_str(str);
|
||
|
}
|
||
|
/* rb_compile_warning() reports only in verbose mode */
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
str = warn_vsprintf(NULL, file, line, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(str);
|
||
|
rb_write_warning_str(str);
|
||
|
}
|
||
|
static VALUE
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
mesg = warning_string(0, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
}
|
||
|
void
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
mesg = warning_string(enc, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
}
|
||
|
/* rb_warning() reports only in verbose mode */
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
mesg = warning_string(0, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
}
|
||
|
#if 0
|
||
| ... | ... | |
|
va_start(args, fmt);
|
||
|
mesg = warning_string(enc, fmt, args);
|
||
|
va_end(args);
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
}
|
||
|
#endif
|
||
| ... | ... | |
|
rb_mErrno = rb_define_module("Errno");
|
||
|
rb_mWarning = rb_define_module("Warning");
|
||
|
rb_define_method(rb_mWarning, "warn", rb_warning_s_warn, 1);
|
||
|
rb_extend_object(rb_mWarning, rb_mWarning);
|
||
|
rb_define_global_function("warn", rb_warn_m, -1);
|
||
|
id_new = rb_intern_const("new");
|
||
| ... | ... | |
|
id_Errno = rb_intern_const("Errno");
|
||
|
id_errno = rb_intern_const("errno");
|
||
|
id_i_path = rb_intern_const("@path");
|
||
|
id_warn = rb_intern_const("warn");
|
||
|
id_iseq = rb_make_internal_id();
|
||
|
}
|
||
| ... | ... | |
|
va_end(args);
|
||
|
rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
|
||
|
rb_str_catf(mesg, ": %s\n", strerror(errno_save));
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
errno = errno_save;
|
||
|
}
|
||
| ... | ... | |
|
va_end(args);
|
||
|
rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
|
||
|
rb_str_catf(mesg, ": %s\n", strerror(errno_save));
|
||
|
rb_write_error_str(mesg);
|
||
|
rb_write_warning_str(mesg);
|
||
|
errno = errno_save;
|
||
|
}
|
||
| test/ruby/test_exception.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_warning_warn
|
||
|
verbose = $VERBOSE
|
||
|
warning = nil
|
||
|
::Warning.class_eval do
|
||
|
alias_method :warn2, :warn
|
||
|
remove_method :warn
|
||
|
define_method(:warn) do |str|
|
||
|
warning = str
|
||
|
end
|
||
|
end
|
||
|
$VERBOSE = true
|
||
|
a = @a
|
||
|
assert_match(/instance variable @a not initialized/, warning)
|
||
|
ensure
|
||
|
$VERBOSE = verbose
|
||
|
::Warning.class_eval do
|
||
|
remove_method :warn
|
||
|
alias_method :warn, :warn2
|
||
|
remove_method :warn2
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »