PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/debug.rb

https://bitbucket.org/tagoh/prune
Ruby | 136 lines | 88 code | 32 blank | 16 comment | 2 complexity | 038610f4bdd537351448de9daa59a4f0 MD5 | raw file
Possible License(s): GPL-2.0
  1. # debug.rb
  2. # Copyright (C) 2005-2009 Akira TAGOH
  3. # Authors:
  4. # Akira TAGOH <akira@tagoh.org>
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330,
  16. # Boston, MA 02111-1307, USA.
  17. require 'rubygems'
  18. gem 'test-unit'
  19. require 'test/unit/testcase'
  20. require 'prune/debug'
  21. class Validator
  22. include PRUNE::Debug
  23. def PRUNE._output(msg)
  24. return msg
  25. end # def _output
  26. alias :debug2 :debug
  27. def debug(cat, fmt, *msg)
  28. debug2(cat, fmt, *msg)
  29. end # def debug
  30. alias :info2 :info
  31. def info(fmt, *msg)
  32. info2(fmt, *msg)
  33. end # def info
  34. alias :warning2 :warning
  35. def warning(fmt, *msg)
  36. warning2(fmt, *msg)
  37. end # def warning
  38. alias :bug2 :bug
  39. def bug(fmt, *msg)
  40. bug2(fmt, *msg)
  41. end # def bug
  42. alias :FIXME2 :FIXME
  43. def FIXME(fmt, *msg)
  44. FIXME2(fmt, *msg)
  45. end # def FIXME
  46. alias :debug_sprintf2 :debug_sprintf
  47. def debug_sprintf(fmt, *args)
  48. debug_sprintf2(fmt, *args)
  49. end # def debug_sprintf
  50. end # class Validator
  51. class TestPRUNE__Debug < Test::Unit::TestCase
  52. def setup
  53. @t = Validator.new
  54. end # def setup
  55. def teardown
  56. end # def teardown
  57. def test_info
  58. assert_equal("INFO ***: foo", @t.info("foo"))
  59. assert_equal("INFO ***: int 10", @t.info("int %d", 10))
  60. assert_equal("INFO ***: str \"foo\"", @t.info("str %s", "foo"))
  61. assert_equal("INFO ***: array [10]", @t.info("array %s", [10]))
  62. assert_equal("INFO ***: hash {\"foo\"=>10}", @t.info("hash %s", {'foo'=>10}))
  63. assert_equal("INFO ***: nil NIL", @t.info("nil %s", nil))
  64. end # def test_info
  65. def test_warning
  66. assert_equal("WARNING ***: foo", @t.warning("foo"))
  67. assert_equal("WARNING ***: int 10", @t.warning("int %d", 10))
  68. assert_equal("WARNING ***: str \"foo\"", @t.warning("str %s", "foo"))
  69. assert_equal("WARNING ***: array [10]", @t.warning("array %s", [10]))
  70. assert_equal("WARNING ***: hash {\"foo\"=>10}", @t.warning("hash %s", {'foo'=>10}))
  71. assert_equal("WARNING ***: nil NIL", @t.warning("nil %s", nil))
  72. end # def test_warning
  73. def test_bug
  74. assert_equal("[BUG] foo", @t.bug("foo"))
  75. assert_equal("[BUG] int 10", @t.bug("int %d", 10))
  76. assert_equal("[BUG] str \"foo\"", @t.bug("str %s", "foo"))
  77. assert_equal("[BUG] array [10]", @t.bug("array %s", [10]))
  78. assert_equal("[BUG] hash {\"foo\"=>10}", @t.bug("hash %s", {'foo'=>10}))
  79. assert_equal("[BUG] nil NIL", @t.bug("nil %s", nil))
  80. end # def test_bug
  81. def test_FIXME
  82. assert_equal("FIXME!!! foo", @t.FIXME("foo"))
  83. assert_equal("FIXME!!! int 10", @t.FIXME("int %d", 10))
  84. assert_equal("FIXME!!! str \"foo\"", @t.FIXME("str %s", "foo"))
  85. assert_equal("FIXME!!! array [10]", @t.FIXME("array %s", [10]))
  86. assert_equal("FIXME!!! hash {\"foo\"=>10}", @t.FIXME("hash %s", {'foo'=>10}))
  87. assert_equal("FIXME!!! nil NIL", @t.FIXME("nil %s", nil))
  88. end # def test_FIXME
  89. def test_debug_sprintf
  90. assert_equal("foo", @t.debug_sprintf("foo"))
  91. assert_equal("int 10", @t.debug_sprintf("int %d", 10))
  92. assert_equal("str \"foo\"", @t.debug_sprintf("str %s", "foo"))
  93. assert_equal("array [10]", @t.debug_sprintf("array %s", [10]))
  94. assert_equal("hash {\"foo\"=>10}", @t.debug_sprintf("hash %s", {'foo'=>10}))
  95. assert_equal("nil NIL", @t.debug_sprintf("nil %s", nil))
  96. end # def test_debug_sprintf
  97. end # class TestPRUNE__Debug
  98. if $0 == __FILE__ then
  99. begin
  100. require 'main'
  101. rescue LoadError
  102. require 'tests/main'
  103. end
  104. end