#!/usr/local/bin/ruby
#
# Copyright 2005 Perforce Software. All rights reserved.
#
require "../../cur.triggers/P4Data.rb"
require "../../cur.triggers/P4Form.rb"
failures = 0
if ischangelist("1") then
# SKIP INIITIALIZATION
printf "System currently populated with test data\n"
else
printf "Populating system with test data\n"
`sh changelist.sh one` # Create changelist 1
`sh changelist.sh two` # Create changelist 2
`sh changelist.sh three` # Create changelist 3
`sh newjob.sh` # Create job000001
`p4 jobspec -i < jobspec.txt` # Define the jobspec
`p4 job -i < goodjob.txt` # Create job000002
`p4 job -i < goodjob.txt` # Create job000003
end
# def ischangelist(value)
printf "\nischangelist() testing:\n"
testcases = [ "1", "2", "3", "4", "", "7", " ", "\"1" ]
expected = [ true, true, true, false, true, false, true, false ]
n = testcases.length - 1
for x in 0..n do
if ischangelist(testcases[x]) == expected[x] then
printf " pass: ischangelist(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: ischangelist(%d:%s) -> %s should be %s\n",
x, testcases[x], ischangelist(testcases[x]), expected[x]
failures += 1
end
end
# def isuserid(value)
printf "\nisuserid() testing:\n"
testcases = [ "one", "two", "three", "nobody", "", "seven", " ", "\"one" ]
expected = [ true, true, true, false, true, false, true, false ]
n = testcases.length - 1
for x in 0..n do
if isuserid(testcases[x]) == expected[x] then
printf " pass: isuserid(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: isuserid(%d:%s) -> %s should be %s\n",
x, testcases[x], isuserid(testcases[x]), expected[x]
failures += 1
end
end
# def isjobid(value)
printf "\nisjobid() testing:\n"
testcases =
["job000001","job000002","job000003","job000004","","job000007","new", " ",
"\"job000001"]
expected =
[ true, true, true, false, true, false, false, true,
false]
n = testcases.length - 1
for x in 0..n do
if isjobid(testcases[x]) == expected[x] then
printf " pass: isjobid(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: isjobid(%d:%s) -> %s should be %s\n",
x, testcases[x], isjobid(testcases[x]), expected[x]
failures += 1
end
end
# def isdepotpath(value)
printf "\nisdepotpath() testing:\n"
testcases =
["//main/...",
"//spec/job/...",
"//spec/job/job000003.p4s",
"...",
"",
" ",
"job000007",
"\"//main/..."]
expected =
[ true, true, true,
false, true, true, false, false]
n = testcases.length - 1
for x in 0..n do
if isdepotpath(testcases[x]) == expected[x] then
printf " pass: isdepotpath(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: isdepotpath(%d:%s) -> %s should be %s\n",
x, testcases[x], isdepotpath(testcases[x]), expected[x]
failures += 1
end
end
# def isfilepath(value)
printf "\nisfilepath() testing:\n"
testcases =
[ "//spec/triggers.p4s",
"//spec/client/twoclient.p4s",
"//spec/job/job000003.p4s",
"//...",
"",
" ",
"job000007",
"\"//spec/triggers.p4s"]
expected =
[ true, true, true,
false, true, true, false, false]
n = testcases.length - 1
for x in 0..n do
if isfilepath(testcases[x]) == expected[x] then
printf " pass: isfilepath(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: isfilepath(%d:%s) -> %s should be %s\n",
x, testcases[x], isfilepath(testcases[x]), expected[x]
failures += 1
end
end
# def islistof(strlist, kind)
# def ischangelist(value)
printf "\nislistof ischangelist() testing:\n"
testcases = [ "1, 2, 3, , ", "", "1",
"1 2 3 ",
"1
2
3
",
"1, 2, 4, , ", "bob", "8",
"4 2 3 ",
"1
2
8
",
"1, 2, \" 3, , " ]
expected = [ true, true,true,
true,
true,
false, false, false,
false,
false, false ]
n = testcases.length - 1
for x in 0..n do
if islistof(testcases[x], "ischangelist") == expected[x] then
printf " pass: islistof ischangelist(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: islistof ischangelist(%d:%s) -> %s should be %s\n",
x, testcases[x], islistof(testcases[x], "ischangelist"), expected[x]
failures += 1
end
end
# def islistof(strlist, kind)
# def isuserid(value)
printf "\nislistof isuserid() testing:\n"
testcases = [ "one, two, three, , ", "", "one",
"one two three ",
"one
two
three
",
"one, two, five, , ", "bob", "eight",
"five two three ",
"one
two
eight
" ]
expected = [ true, true,true,
true,
true,
false, false, false,
false,
false ]
n = testcases.length - 1
for x in 0..n do
if islistof(testcases[x], "isuserid") == expected[x] then
printf " pass: islistof isuserid(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: islistof isuserid(%d:%s) -> %s should be %s\n",
x, testcases[x], islistof(testcases[x], "isuserid"), expected[x]
failures += 1
end
end
# def islistof(strlist, kind)
# def isjobid(value)
printf "\nislistof isjobid() testing:\n"
testcases = [ "job000001, job000002, job000003, , ", "", "job000001",
"job000001 job000002 job000003 ",
"job000001
job000002
job000003
",
"job000001, job000002, job000004, , ", "bob", "eight",
"five job000002 job000003 ",
"job000001
job000002
eight
" ]
expected = [ true, true,true,
true,
true,
false, false, false,
false,
false ]
n = testcases.length - 1
for x in 0..n do
if islistof(testcases[x], "isjobid") == expected[x] then
printf " pass: islistof isjobid(%d:%s) -> %s\n",
x, testcases[x], expected[x]
else
printf " FAIL: islistof isjobid(%d:%s) -> %s should be %s\n",
x, testcases[x], islistof(testcases[x], "isjobid"), expected[x]
failures += 1
end
end
# The following are assumed to pass if the above pass
# def islistof isdepotpath(value)
# def islistof isfilepath(value)
printf "\n"
if failures > 0 then
printf "ALL TESTS DID NOT PASS: %d failed\n", failures
exit 1
else
printf "All tests PASSED\n"
exit 0
end