From 2bf399c240938ba51069348f986fa5d65135a808 Mon Sep 17 00:00:00 2001 From: chick Date: Thu, 1 Aug 2019 17:04:45 -0700 Subject: Followup to PR #1142 - use scala.io.Source instead of io.Source - .toList cleaner way to force stream to be read. - clear old commented out code in ProtoBufSpec --- src/main/scala/firrtl/FileUtils.scala | 15 ++++++++------- src/test/scala/firrtlTests/ProtoBufSpec.scala | 6 ------ 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/main/scala/firrtl/FileUtils.scala b/src/main/scala/firrtl/FileUtils.scala index 74919f20..1007eb2a 100644 --- a/src/main/scala/firrtl/FileUtils.scala +++ b/src/main/scala/firrtl/FileUtils.scala @@ -98,7 +98,7 @@ object FileUtils { * @param fileName The file to read */ def getLines(fileName: String): Seq[String] = { - val source = io.Source.fromFile(fileName) + val source = scala.io.Source.fromFile(fileName) val lines = source.getLines() source.close() lines.toSeq @@ -110,7 +110,7 @@ object FileUtils { * @param file a java File to be read */ def getLines(file: File): Seq[String] = { - val source = io.Source.fromFile(file) + val source = scala.io.Source.fromFile(file) val lines = source.getLines() source.close() lines.toSeq @@ -122,7 +122,7 @@ object FileUtils { * @param fileName The file to read */ def getText(fileName: String): String = { - val source = io.Source.fromFile(fileName) + val source = scala.io.Source.fromFile(fileName) val text = source.mkString source.close() text @@ -134,7 +134,7 @@ object FileUtils { * @param file a java File to be read */ def getText(file: File): String = { - val source = io.Source.fromFile(file) + val source = scala.io.Source.fromFile(file) val text = source.mkString source.close() text @@ -148,8 +148,9 @@ object FileUtils { */ def getLinesResource(resourceName: String): Seq[String] = { val inputStream = getClass.getResourceAsStream(resourceName) - val text = io.Source.fromInputStream(inputStream).getLines().toSeq - text.length // This forces lazy buffer to reify, please suggest a better solution + // the .toList at the end is critical to force stream to be read. + // Without it the lazy evaluation can cause failure in MultiThreadingSpec + val text = scala.io.Source.fromInputStream(inputStream).getLines().toList inputStream.close() text } @@ -162,7 +163,7 @@ object FileUtils { */ def getTextResource(resourceName: String): String = { val inputStream = getClass.getResourceAsStream(resourceName) - val text = io.Source.fromInputStream(inputStream).mkString + val text = scala.io.Source.fromInputStream(inputStream).mkString inputStream.close() text } diff --git a/src/test/scala/firrtlTests/ProtoBufSpec.scala b/src/test/scala/firrtlTests/ProtoBufSpec.scala index 3d46e291..526a194c 100644 --- a/src/test/scala/firrtlTests/ProtoBufSpec.scala +++ b/src/test/scala/firrtlTests/ProtoBufSpec.scala @@ -2,8 +2,6 @@ package firrtlTests -import java.io.{ByteArrayInputStream, ByteArrayOutputStream} - import firrtl.FirrtlProtos.Firrtl import firrtl._ import firrtl.ir._ @@ -30,10 +28,6 @@ class ProtoBufSpec extends FirrtlFlatSpec { for (FirrtlResourceTest(name, dir) <- firrtlResourceTests) { s"$name" should "work with Protobuf serialization and deserialization" in { -// val stream = getClass.getResourceAsStream(s"$dir/$name.fir") -// val circuit = parse(scala.io.Source.fromInputStream(stream).getLines.mkString("\n")) -// stream.close() - val circuit = parse(FileUtils.getTextResource(s"$dir/$name.fir")) // Test ToProto and FromProto -- cgit v1.2.3