You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.1KB

  1. // ---
  2. //
  3. // $Id: cpptest-compileroutput.h,v 1.3 2005/06/08 08:08:06 nilu Exp $
  4. //
  5. // CppTest - A C++ Unit Testing Framework
  6. // Copyright (c) 2003 Niklas Lundell
  7. //
  8. // ---
  9. //
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Lesser General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2 of the License, or (at your option) any later version.
  14. //
  15. // This library is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. // Lesser General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Lesser General Public
  21. // License along with this library; if not, write to the
  22. // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. // Boston, MA 02111-1307, USA.
  24. //
  25. // ---
  26. /** \file */
  27. #ifndef CPPTEST_COMPILEROUTPUT_H
  28. #define CPPTEST_COMPILEROUTPUT_H
  29. #include "cpptest-output.h"
  30. namespace Test
  31. {
  32. /// \brief Compiler-like output handler.
  33. ///
  34. /// %Test suite output handler that only outputs failures in compiler
  35. /// warning/error format. This way, you can use your IDE to browse between
  36. /// failures.
  37. ///
  38. /// The output format is configurable to be able to emulate different
  39. /// compiler outputs. The following modifiers exist:
  40. /// - \e %file Outputs the file containing the test function.
  41. /// - \e %line Line number for the the test function.
  42. /// - \e %text Expression (or message) that caused the assertment.
  43. /// Note that each modifier can only be specified once.
  44. ///
  45. class CompilerOutput : public Output
  46. {
  47. public:
  48. /// \brief Compiler output exception.
  49. ///
  50. /// Indicates that an invalid message format was given when creating
  51. /// a compiler output. The failing format may be retrieved using the
  52. /// what() method.
  53. ///
  54. class InvalidFormat : public std::logic_error
  55. {
  56. public:
  57. InvalidFormat(const std::string& what)
  58. : std::logic_error(what) {}
  59. };
  60. /// Pre-defined compiler output formats.
  61. ///
  62. enum Format
  63. {
  64. /// Generic compiler format, which equals:
  65. /// <tt>%%file:%%line: %%text</tt>
  66. ///
  67. Generic,
  68. /// <a href="http://www.borland.com/products/downloads/download_cbuilder.html">
  69. /// Borland C++ Compiler</a> (BCC) format, which equals:
  70. /// <tt>Error cpptest %%file %%line: %%text</tt>.
  71. ///
  72. BCC,
  73. /// <a href="http://gcc.gnu.org">GNU Compiler Collection</a>
  74. /// (GCC) format, which equals:
  75. /// <tt>%%file:%%line: %%text</tt>
  76. ///
  77. GCC,
  78. /// <a href="http://www.microsoft.com">Microsoft Visual C++</a>
  79. /// (MSVC) format, which equals:
  80. /// <tt>%%file(%%line) : %%text</tt>
  81. ///
  82. MSVC
  83. };
  84. explicit CompilerOutput(Format format = Generic,
  85. std::ostream& stream = std::cout);
  86. explicit CompilerOutput(const std::string& format,
  87. std::ostream& stream = std::cout);
  88. virtual void assertment(const Source& s);
  89. private:
  90. std::string _format;
  91. std::ostream& _stream;
  92. };
  93. } // namespace Test
  94. #endif // #ifndef CPPTEST_COMPILEROUTPUT_H