forked from gfredericks/quinedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
61 lines (52 loc) · 1.41 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Run this with `ruby test.rb`
require 'test/unit'
class ILoveOOP < Test::Unit::TestCase
def quine?(file)
sha1 = `sha1sum #{file}`.split(/\s/)[0]
sha2 = `#{file} 2>/dev/null | sha1sum`.split(/\s/)[0]
sha1 == sha2
end
def test_quineness
assert(quine?("./quinedb"), "isn't even a quine")
end
def setup
`rm -rf tmp/test`
`mkdir -p tmp/test`
`cp quinedb tmp/test/quinedb`
end
def teardown
`rm -rf tmp`
end
def pr_str s
s2 = ""
(0...(s.length)).each{|i|s2 << "\\#{s[i]}"}
s2
end
def cmd *args
args = args.map{|x|pr_str x}.join(" ")
`tmp/test/quinedb #{args} > tmp/test/out 2> tmp/test/err`
`mv tmp/test/out tmp/test/quinedb`
`chmod +x tmp/test/quinedb`
res = `cat tmp/test/err`
`rm tmp/test/err`
res.strip
end
def test_basic_crud
assert(cmd("keys") == "")
assert(quine?("tmp/test/quinedb"))
assert(cmd("set","k","v") == "OK")
assert(quine?("tmp/test/quinedb"))
assert(cmd("keys") == "k")
assert(quine?("tmp/test/quinedb"))
assert(cmd("set","k2","v2") == "OK")
assert(quine?("tmp/test/quinedb"))
assert(cmd("keys").split(/\n/).sort == %w(k k2))
assert(cmd("get","k") == "v")
assert(cmd("get","k2") == "v2")
assert(cmd("delete","k2") == "OK")
assert(cmd("get","k2") == "")
assert(cmd("get","k") == "v")
assert(quine?("tmp/test/quinedb"))
end
# TODO: write some more tests
end