![JAR search and dependency download from the Maven repository](/logo.png)
org.scalatest.tools.PrintReporter.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest.tools
// SKIP-SCALATESTJS,NATIVE-START
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
// SKIP-SCALATESTJS,NATIVE-END
import java.io.OutputStreamWriter
import java.io.OutputStream
import java.io.PrintWriter
import org.scalatest.events._
import PrintReporter._
/**
* A Reporter
that prints test status information to
* a Writer
, OutputStream
, or file.
*
* @author Bill Venners
*/
private[scalatest] abstract class PrintReporter(
pw: PrintWriter,
presentAllDurations: Boolean,
presentInColor: Boolean,
presentShortStackTraces: Boolean,
presentFullStackTraces: Boolean,
presentUnformatted: Boolean,
presentReminder: Boolean,
presentReminderWithShortStackTraces: Boolean,
presentReminderWithFullStackTraces: Boolean,
presentReminderWithoutCanceledTests: Boolean,
presentFilePathname: Boolean,
presentJson: Boolean
) extends StringReporter(
presentAllDurations,
presentInColor,
presentShortStackTraces,
presentFullStackTraces,
presentUnformatted,
presentReminder,
presentReminderWithShortStackTraces,
presentReminderWithFullStackTraces,
presentReminderWithoutCanceledTests,
presentFilePathname,
presentJson
) {
/**
* Construct a PrintReporter
with passed
* OutputStream
. Information about events reported to instances of this
* class will be written to the OutputStream
using the
* default character encoding.
*
* @param os the OutputStream
to which to print reported info
* @throws NullArgumentException if passed os
reference is null
*/
def this( // Used by subclasses StandardOutReporter and StandardErrReporter
os: OutputStream,
presentAllDurations: Boolean,
presentInColor: Boolean,
presentShortStackTraces: Boolean,
presentFullStackTraces: Boolean,
presentUnformatted: Boolean,
presentReminder: Boolean,
presentReminderWithShortStackTraces: Boolean,
presentReminderWithFullStackTraces: Boolean,
presentReminderWithoutCanceledTests: Boolean,
presentFilePathname: Boolean,
presentJson: Boolean
) =
this(
new PrintWriter(
new OutputStreamWriter(
new BufferedOutputStream(os, BufferSize)
)
),
presentAllDurations,
presentInColor,
presentShortStackTraces,
presentFullStackTraces,
presentUnformatted,
presentReminder,
presentReminderWithShortStackTraces,
presentReminderWithFullStackTraces,
presentReminderWithoutCanceledTests,
presentFilePathname,
presentJson
)
// SKIP-SCALATESTJS,NATIVE-START
/**
* Construct a PrintReporter
with passed
* String
file name. Information about events reported to instances of this
* class will be written to the specified file using the
* default character encoding.
*
* @param filename the String
name of the file to which to print reported info
* @throws NullArgumentException if passed filename
reference is null
* @throws IOException if unable to open the specified file for writing
*/
def this( // Used by subclass FileReporter
filename: String,
presentAllDurations: Boolean,
presentInColor: Boolean,
presentShortStackTraces: Boolean,
presentFullStackTraces: Boolean,
presentUnformatted: Boolean,
presentReminder: Boolean,
presentReminderWithShortStackTraces: Boolean,
presentReminderWithFullStackTraces: Boolean,
presentReminderWithoutCanceledTests: Boolean,
presentFilePathname: Boolean,
presentJson: Boolean
) =
this(
new PrintWriter(new BufferedOutputStream(new FileOutputStream(new File(filename)), BufferSize)),
presentAllDurations,
presentInColor,
presentShortStackTraces,
presentFullStackTraces,
presentUnformatted,
presentReminder,
presentReminderWithShortStackTraces,
presentReminderWithFullStackTraces,
presentReminderWithoutCanceledTests,
presentFilePathname,
presentJson
)
// SKIP-SCALATESTJS,NATIVE-END
protected def printPossiblyInColor(fragment: Fragment): Unit = {
pw.println(fragment.toPossiblyColoredText(presentInColor))
}
protected def printNoColor(text: String): Unit = {
pw.println(text)
}
override def apply(event: Event): Unit = {
super.apply(event)
pw.flush()
}
// Closes the print writer. Subclasses StandardOutReporter and StandardErrReporter override dispose to do nothing
// so that those aren't closed.
override def dispose(): Unit = {
pw.close()
}
// We subtract one from test reports because we add "- " in front, so if one is actually zero, it will come here as -1
// private def indent(s: String, times: Int) = if (times <= 0) s else (" " * times) + s
// Stupid properties file won't let me put spaces at the beginning of a property
// " {0}" comes out as "{0}", so I can't do indenting in a localizable way. For now
// just indent two space to the left. // if (times <= 0) s
// else Resources.indentOnce(indent(s, times - 1))
}
private[scalatest] object PrintReporter {
final val BufferSize = 4096
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy