Skip to content

Implement open(filename, mode) and use it #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_open: addition of a test for stream files
  • Loading branch information
jvdp1 committed Jan 4, 2020
commit 2f1a0e813dcdaec0e881663d5ce9942b61a260a3
7 changes: 5 additions & 2 deletions src/tests/io/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ OBJS = ../../stdlib_experimental_error.o \
.PHONY: all clean
.SUFFIXES: .f90 .o

all: test_loadtxt test_savetxt
all: test_loadtxt test_savetxt test_open

test_loadtxt: test_loadtxt.f90 $(OBJS)
$(FC) $(FCFLAGS) $(CPPFLAGS) $< -o $@ $(OBJS)

test_savetxt: test_savetxt.f90 $(OBJS)
$(FC) $(FCFLAGS) $(CPPFLAGS) $< -o $@ $(OBJS)

test_open: test_open.f90 $(OBJS)
$(FC) $(FCFLAGS) $(CPPFLAGS) $< -o $@ $(OBJS)

%.o: %.mod

clean:
$(RM) test_loadtxt test_savetxt
$(RM) test_loadtxt test_savetxt test_open
$(RM) *.o *.mod
27 changes: 27 additions & 0 deletions src/tests/io/test_open.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ program test_open
character(:), allocatable :: filename
integer :: u, a(3)

! Text file
filename = get_outpath() // "/io_open.dat"

! Test mode "w"
Expand All @@ -31,6 +32,32 @@ program test_open
close(u)



! Stream file
filename = get_outpath() // "/io_open.stream"

! Test mode "w"
u = open(filename, "wb")
write(u) 1, 2, 3
close(u)

! Test mode "r"
u = open(filename, "rb")
read(u) a
call assert(all(a == [1, 2, 3]))
close(u)

! Test mode "a"
u = open(filename, "ab")
write(u) 4, 5, 6
close(u)
u = open(filename, "rb")
read(u) a
call assert(all(a == [1, 2, 3]))
read(u) a
call assert(all(a == [4, 5, 6]))
close(u)

contains

function get_outpath() result(outpath)
Expand Down