Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
daa02fe6
Commit
daa02fe6
authored
Mar 22, 2017
by
Yash Patel
Committed by
Dylan Trotter
Mar 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for a+ and w+ modes (files) (#271)
parent
83bb9538
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
runtime/file.go
runtime/file.go
+5
-0
runtime/file_test.go
runtime/file_test.go
+10
-2
No files found.
runtime/file.go
View file @
daa02fe6
...
...
@@ -127,6 +127,11 @@ func fileInit(f *Frame, o *Object, args Args, _ KWArgs) (*Object, *BaseException
flag
=
os
.
O_RDONLY
case
"r+"
,
"r+b"
:
flag
=
os
.
O_RDWR
// Difference between r+ and a+ is that a+ automatically creates file.
case
"a+"
:
flag
=
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_APPEND
case
"w+"
:
flag
=
os
.
O_RDWR
|
os
.
O_CREATE
case
"w"
,
"wb"
:
flag
=
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_TRUNC
default
:
...
...
runtime/file_test.go
View file @
daa02fe6
...
...
@@ -34,7 +34,6 @@ func TestFileInit(t *testing.T) {
{
args
:
wrapArgs
(
newObject
(
FileType
),
f
.
path
),
want
:
None
},
{
args
:
wrapArgs
(
newObject
(
FileType
)),
wantExc
:
mustCreateException
(
TypeErrorType
,
"'__init__' requires 2 arguments"
)},
{
args
:
wrapArgs
(
newObject
(
FileType
),
f
.
path
,
"abc"
),
wantExc
:
mustCreateException
(
ValueErrorType
,
`invalid mode string: "abc"`
)},
{
args
:
wrapArgs
(
newObject
(
FileType
),
f
.
path
,
"w+"
),
wantExc
:
mustCreateException
(
ValueErrorType
,
`invalid mode string: "w+"`
)},
{
args
:
wrapArgs
(
newObject
(
FileType
),
"nonexistent-file"
),
wantExc
:
mustCreateException
(
IOErrorType
,
"open nonexistent-file: no such file or directory"
)},
}
for
_
,
cas
:=
range
cases
{
...
...
@@ -303,7 +302,7 @@ func TestFileWrite(t *testing.T) {
t
.
Fatalf
(
"Chdir(%q) failed: %s"
,
dir
,
err
)
}
defer
os
.
Chdir
(
oldWd
)
for
_
,
filename
:=
range
[]
string
{
"truncate.txt"
,
"readonly.txt"
,
"append.txt"
,
"rplus.txt"
}
{
for
_
,
filename
:=
range
[]
string
{
"truncate.txt"
,
"readonly.txt"
,
"append.txt"
,
"rplus.txt"
,
"aplus.txt"
,
"wplus.txt"
}
{
if
err
:=
ioutil
.
WriteFile
(
filename
,
[]
byte
(
filename
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"ioutil.WriteFile(%q) failed: %s"
,
filename
,
err
)
}
...
...
@@ -312,7 +311,16 @@ func TestFileWrite(t *testing.T) {
{
args
:
wrapArgs
(
"noexist.txt"
,
"w"
,
"foo
\n
bar"
),
want
:
NewStr
(
"foo
\n
bar"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"truncate.txt"
,
"w"
,
"new contents"
),
want
:
NewStr
(
"new contents"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"append.txt"
,
"a"
,
"
\n
bar"
),
want
:
NewStr
(
"append.txt
\n
bar"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"rplus.txt"
,
"r+"
,
"fooey"
),
want
:
NewStr
(
"fooey.txt"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"noexistplus1.txt"
,
"r+"
,
"pooey"
),
wantExc
:
mustCreateException
(
IOErrorType
,
"open noexistplus1.txt: no such file or directory"
)},
{
args
:
wrapArgs
(
"aplus.txt"
,
"a+"
,
"
\n
apper"
),
want
:
NewStr
(
"aplus.txt
\n
apper"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"noexistplus3.txt"
,
"a+"
,
"snappbacktoreality"
),
want
:
NewStr
(
"snappbacktoreality"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"wplus.txt"
,
"w+"
,
"destructo"
),
want
:
NewStr
(
"destructo"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"noexistplus2.txt"
,
"w+"
,
"wapper"
),
want
:
NewStr
(
"wapper"
)
.
ToObject
()},
{
args
:
wrapArgs
(
"readonly.txt"
,
"r"
,
"foo"
),
wantExc
:
mustCreateException
(
IOErrorType
,
"write readonly.txt: bad file descriptor"
)},
}
for
_
,
cas
:=
range
cases
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment