Re: file reading

Raphael Crawford-Marks <[email protected]>
Newsgroups gmane.comp.breve
Message-ID <[email protected]>
After some more investigation it looks like there is a bug.

1) open-for-reading returns TRUE regardless of whether or not the file existed.
 2) If the file does *not* exist, calling read-line will cause the simulation to
stop because the File object is uninitialized
3) However, testing to see if the File object is initialized will return true,
even if the file does not exist.

Here is some code to demonstrate this:

**********************************************************************
#Before running this simulation, please create a file called 'foo'.
@use Control.
@use File.

Controller fileTestControl.

Control : fileTestControl {
    + variables:
	file (object).
	result (string).

    + to init:
	file = new File.

	print "About to open-for-reading a file that does exist (\"foo\").".
	if (file open-for-reading with-file "foo"):
	  print "Successfully Opened file \"foo\"!".
	else print "Failure opening file \"foo\".".

	if file: {
	  print "About to read-line from \"foo\".".
	  result = file read-line.
	  print "Result of read-line: $result".
	} else "You should not see this because \"foo\" exists.".

	print "About to open-for-reading a file that doesn't exist (\"asdfjkl\").".
	if (file open-for-reading with-file "asdfjkl"):
	  print "Successfully Opened file \"asdfjkl\"!".
	else print "Failure opening file \"asdfjkl\".".

	if file: {
	  print "About to read-line from \"asdfjkl\".".
	  result = file read-line.
	  print "Result of read-line: $result".
	} else "You should see this because \"asdfjkl\" DOES NOT EXIST.".

    + to iterate:
	die "Test Over.".
}
**********************************************************************

And the output on my machine:

**********************************************************************
[raphaelc@localhost breve_linux]$ ./brun_cli testFileRead.tz
About to open-for-reading a file that does exist ("foo").
Successfully Opened file "foo"!
About to read-line from "foo".
Result of read-line: This is the first line of foo.
About to open-for-reading a file that doesn't exist ("asdfjkl").
Could not locate file "asdfjkl"
Could not open file "asdfjkl" for reading: Bad address
Successfully Opened file "asdfjkl"!
About to read-line from "asdfjkl".
**********************************************************************

-- 
Raphael Crawford-Marks
http://user-error.net


Quoting Raphael Crawford-Marks <[email protected]>:

> What is the behavior of open-for-reading and the various read methods for
> the
> File object if the desired file does not exist?
> 
> Thanks,
> 
> Raphael
> 
> 
> -- 
> Raphael Crawford-Marks
> http://user-error.net
> 
_______________________________________________
breve mailing list
[email protected]
http://www.spiderland.org/mailman/listinfo/breve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.