Possible Error in Boo Implementation of StreamReader
A poster on the Google Boo group responded. The problem was that there were two StreamReader functions, one of which took a Stream as its parameter and one a String. Boo was guessing that I was using the Stream version when in fact I was using the string. The solution was to specify the parameter as
filename as String
I am using a .7 version of Boo and Nunit in SharpDevelop 2 under Windows.
The first of the following two scripts produces an error.
Yet the only difference between the two scripts is that in the error-prone version StreamReader uses a passed string parameter containing the name of the file. The non-error-prone version uses a hard-coded string value. Yet the unit test shows that the values of the hard-coded string and of the passed parameter are the same.
The first script gives me this error:
Exception System.InvalidCastException was thrown in debugee:Unable to cast object of type 'System.String' to type 'System.IO.Stream'.
readLog() - C:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\ParseLogsBoo\Program.boo:15,0Main() - C:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\ParseLogsBoo\Program.boo:21,0
The script producing the error is:
namespace ParseLogsBoo
import System
import System.Collections
import System.Xml from System.Xml
import System.IO
import System.Reflection
import NUnit.Framework from "nunit.framework"
[TestFixture]
class ParseLog:
[Test]
....def readLog(filename):
........if File.Exists(filename):
............using input = StreamReader(filename):
................Assert.AreEqual(filename,"c: \\logs\\shortlog.txt")
testfile = "c: \\logs\\shortlog.txt"
myParseLog = ParseLog()
myParseLog.readLog(testfile)
However, the following script runs without error:
namespace ParseLogsBoo
import System
import System.Collections
import System.Xml from System.Xml
import System.IO
import System.Reflection
import NUnit.Framework from "nunit.framework"
[TestFixture]
class ParseLog:
[Test]
....def readLog(filename):
........if File.Exists(filename):
............using input = StreamReader("c: \\logs\\shortlog.txt"):
................Assert.AreEqual(filename,"c: \\logs\\shortlog.txt")
testfile = "c: \\logs\\shortlog.txt"
myParseLog = ParseLog()
myParseLog.readLog(testfile)
filename as String
I am using a .7 version of Boo and Nunit in SharpDevelop 2 under Windows.
The first of the following two scripts produces an error.
Yet the only difference between the two scripts is that in the error-prone version StreamReader uses a passed string parameter containing the name of the file. The non-error-prone version uses a hard-coded string value. Yet the unit test shows that the values of the hard-coded string and of the passed parameter are the same.
The first script gives me this error:
Exception System.InvalidCastException was thrown in debugee:Unable to cast object of type 'System.String' to type 'System.IO.Stream'.
readLog() - C:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\ParseLogsBoo\Program.boo:15,0Main() - C:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\ParseLogsBoo\Program.boo:21,0
The script producing the error is:
namespace ParseLogsBoo
import System
import System.Collections
import System.Xml from System.Xml
import System.IO
import System.Reflection
import NUnit.Framework from "nunit.framework"
[TestFixture]
class ParseLog:
[Test]
....def readLog(filename):
........if File.Exists(filename):
............using input = StreamReader(filename):
................Assert.AreEqual(filename,"c: \\logs\\shortlog.txt")
testfile = "c: \\logs\\shortlog.txt"
myParseLog = ParseLog()
myParseLog.readLog(testfile)
However, the following script runs without error:
namespace ParseLogsBoo
import System
import System.Collections
import System.Xml from System.Xml
import System.IO
import System.Reflection
import NUnit.Framework from "nunit.framework"
[TestFixture]
class ParseLog:
[Test]
....def readLog(filename):
........if File.Exists(filename):
............using input = StreamReader("c: \\logs\\shortlog.txt"):
................Assert.AreEqual(filename,"c: \\logs\\shortlog.txt")
testfile = "c: \\logs\\shortlog.txt"
myParseLog = ParseLog()
myParseLog.readLog(testfile)

0 Comments:
Post a Comment
<< Home