lib/rio/assert.rb in rio-0.5.1 vs lib/rio/assert.rb in rio-0.6.0
- old
+ new
@@ -1,8 +1,8 @@
#--
# ===========================================================================
-# Copyright (c) 2005-2012 Christopher Kleckner
+# Copyright (c) 2005-2017 Christopher Kleckner
# All rights reserved
#
# This file is part of the Rio library for ruby.
#
# Rio is free software; you can redistribute it and/or modify
@@ -31,12 +31,10 @@
def ok(a,b,msg=nil)
puts "PASS" + (msg.nil? ? "" : ": #{msg}")
end
def nok(a,b,msg=nil)
calla = caller.grep(/^#{Regexp.escape($0)}/)
- #calla = caller
- #calls = " " + (calla[0] || "")
calls = calla.join("\n") + "\n"
puts "FAIL" + (msg.nil? ? "" : ": #{msg}") + calls
puts " exp: #{a.inspect}"
puts " was: #{b.inspect}"
end
@@ -50,13 +48,10 @@
rescue exc
return ok(exc,nil,msg)
end
return nok(exc,nil,msg)
end
-
-
-
def assert_equal(a,b,msg=nil)
if a == b
ok(a,b,msg)
else
@@ -75,11 +70,11 @@
ok(nil,nil,msg)
else
nok(nil,nil,msg)
end
end
-
+
def assert_not_equal(a,b,msg=nil)
if a != b
ok(a,b,msg)
else
nok(a,b,msg)
@@ -129,58 +124,47 @@
end
def assert_equal_s(a,b,msg=nil) assert_equal(a.to_s,b.to_s,msg) end
def assert_equal_a(a,b,msg=nil) assert_equal(a.sort,b.sort,msg) end
-
-
-
-
-
-
def assert!(a,msg="negative assertion")
assert((!(a)),msg)
end
def smap(a) a.map { |el| el.to_s } end
-
-
-
-
-
- def assert_array_equal(a,b,msg="array same regardless of order")
- if a.nil?
- assert_nil(b)
- elsif b.nil?
- assert_nil(a)
- else
- assert_equal(smap(a).sort,smap(b).sort,msg)
- end
+ def assert_array_equal(a,b,msg="array same regardless of order")
+ if a.nil?
+ assert_nil(b)
+ elsif b.nil?
+ assert_nil(a)
+ else
+ assert_equal(smap(a).sort,smap(b).sort,msg)
end
- def assert_dirs_equal(exp,d,msg="")
- exp.each do |ent|
- ds = rio(d,ent.filename)
- assert_equal(ent.symlink?,ds.symlink?,"both symlinks, or not")
- unless ent.symlink?
- assert(ds.exist?,"entry '#{ds}' exists")
- end
- assert_equal(ent.ftype,ds.ftype,"same ftype")
- assert_rios_equal(ent,ds,"sub rios are the same")
+ end
+ def assert_dirs_equal(exp,d,msg="")
+ exp.each do |ent|
+ ds = rio(d,ent.filename)
+ assert_equal(ent.symlink?,ds.symlink?,"both symlinks, or not")
+ unless ent.symlink?
+ assert(ds.exist?,"entry '#{ds}' exists")
end
+ assert_equal(ent.ftype,ds.ftype,"same ftype")
+ assert_rios_equal(ent,ds,"sub rios are the same")
end
- def assert_rios_equal(exp,ans,msg="")
- case
- when exp.symlink?
- assert(ans.symlink?,"entry is a symlink")
- assert_equal(exp.readlink,ans.readlink,"symlinks read the same")
- when exp.file?
- assert(ans.file?,"entry is a file")
- assert_equal(exp.chomp.lines[],ans.chomp.lines[],"file has same contents")
- when exp.dir?
- assert(ans.dir?,"entry is a dir")
- assert_dirs_equal(exp,ans,"directories are the same")
- end
+ end
+ def assert_rios_equal(exp,ans,msg="")
+ case
+ when exp.symlink?
+ assert(ans.symlink?,"entry is a symlink")
+ assert_equal(exp.readlink,ans.readlink,"symlinks read the same")
+ when exp.file?
+ assert(ans.file?,"entry is a file")
+ assert_equal(exp.chomp.lines[],ans.chomp.lines[],"file has same contents")
+ when exp.dir?
+ assert(ans.dir?,"entry is a dir")
+ assert_dirs_equal(exp,ans,"directories are the same")
end
+ end
end
end