tests: add test_path
authorJean Privat <jean@pryen.org>
Tue, 21 Jul 2015 13:20:23 +0000 (09:20 -0400)
committerJean Privat <jean@pryen.org>
Wed, 22 Jul 2015 12:48:48 +0000 (08:48 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/sav/test_path.res [new file with mode: 0644]
tests/sav/test_path_args1.res [new file with mode: 0644]
tests/test_path.args [new file with mode: 0644]
tests/test_path.nit [new file with mode: 0644]

diff --git a/tests/sav/test_path.res b/tests/sav/test_path.res
new file mode 100644 (file)
index 0000000..a258212
--- /dev/null
@@ -0,0 +1 @@
+require the name of the output directory
diff --git a/tests/sav/test_path_args1.res b/tests/sav/test_path_args1.res
new file mode 100644 (file)
index 0000000..a013db5
--- /dev/null
@@ -0,0 +1,82 @@
+* out/test_path_args1.write
+simplified: out/test_path_args1.write
+filename: test_path_args1.write
+dir: out
+exists: true
+  error? nope
+stat: is_dir=true is_reg=false
+  error? nope
+open: out/test_path_args1.write
+  error? nope
+first_line: 
+  error? Cannot read `out/test_path_args1.write`: Is a directory
+content: 0 chars
+  error? Cannot read `out/test_path_args1.write`: Is a directory
+content: 0 bytes
+  error? Cannot read `out/test_path_args1.write`: Is a directory
+content: 0 lines
+  error? Cannot read `out/test_path_args1.write`: Is a directory
+content: 0 files
+  error? nope
+* out/test_path_args1.write/file.txt
+simplified: out/test_path_args1.write/file.txt
+filename: file.txt
+dir: out/test_path_args1.write
+exists: false
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+stat: nope
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+open: out/test_path_args1.write/file.txt
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+first_line: 
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+content: 0 chars
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+content: 0 bytes
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+content: 0 lines
+  error? Cannot open `out/test_path_args1.write/file.txt`: No such file or directory
+content: 0 files
+  error? Cannot list directory `out/test_path_args1.write/file.txt`: No such file or directory
+* out/test_path_args1.write/file.txt
+simplified: out/test_path_args1.write/file.txt
+filename: file.txt
+dir: out/test_path_args1.write
+exists: true
+  error? nope
+stat: is_dir=false is_reg=true
+  error? nope
+open: out/test_path_args1.write/file.txt
+  error? nope
+first_line: hello world!
+  error? nope
+content: 12 chars
+  error? nope
+content: 12 bytes
+  error? nope
+content: 1 lines
+  error? nope
+content: 0 files
+  error? Cannot list directory `out/test_path_args1.write/file.txt`: Not a directory
+* out/test_path_args1.write/dir
+simplified: out/test_path_args1.write/dir
+filename: dir
+dir: out/test_path_args1.write
+exists: true
+  error? nope
+stat: is_dir=true is_reg=false
+  error? nope
+open: out/test_path_args1.write/dir
+  error? nope
+first_line: 
+  error? Cannot read `out/test_path_args1.write/dir`: Is a directory
+content: 0 chars
+  error? Cannot read `out/test_path_args1.write/dir`: Is a directory
+content: 0 bytes
+  error? Cannot read `out/test_path_args1.write/dir`: Is a directory
+content: 0 lines
+  error? Cannot read `out/test_path_args1.write/dir`: Is a directory
+content: 1 files
+  error? nope
+dir/
+file.txt
diff --git a/tests/test_path.args b/tests/test_path.args
new file mode 100644 (file)
index 0000000..a62688b
--- /dev/null
@@ -0,0 +1 @@
+$WRITE
diff --git a/tests/test_path.nit b/tests/test_path.nit
new file mode 100644 (file)
index 0000000..2230579
--- /dev/null
@@ -0,0 +1,71 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+fun test_path(p: Path)
+do
+       print "* {p}"
+       print "simplified: {p.simplified}"
+       print "filename: {p.filename}"
+       print "dir: {p.dir}"
+       var e = p.exists
+       print "exists: {e}"
+       print "  error? {p.last_error or else "nope"}"
+       var s = p.stat
+       if s == null then
+               print "stat: nope"
+       else
+               print "stat: is_dir={s.is_dir} is_reg={s.is_reg}"
+       end
+       print "  error? {p.last_error or else "nope"}"
+       var stream = p.open_ro
+       print "open: {stream.path or else "-"}"
+       print "  error? {p.last_error or else "nope"}"
+       print "first_line: {stream.read_line}"
+       stream.close
+       print "  error? {stream.last_error or else "nope"}"
+       var txt = p.read_all
+       print "content: {txt.length} chars"
+       print "  error? {p.last_error or else "nope"}"
+       var bin = p.read_all_bytes
+       print "content: {bin.length} bytes"
+       print "  error? {p.last_error or else "nope"}"
+       var lines = p.read_lines
+       print "content: {lines.length} lines"
+       print "  error? {p.last_error or else "nope"}"
+
+       var files = p.files
+       print "content: {files.length} files"
+       print "  error? {p.last_error or else "nope"}"
+end
+
+if args.length != 1 then
+       print "require the name of the output directory"
+       return
+end
+
+var base = args.first
+base.mkdir
+test_path(base.to_path)
+
+var f = (base/"file.txt").to_path
+test_path(f)
+
+"hello world!".write_to_file(f.to_s)
+test_path(f)
+
+var dn = base / "dir"
+var d = dn.to_path
+dn.mkdir
+"goodby world!".write_to_file(dn/"file.txt")
+test_path(d)