diff options
Diffstat (limited to 'tests/modules')
| -rw-r--r-- | tests/modules/devel/git/test.lua | 28 | ||||
| -rwxr-xr-x | tests/modules/hello/test.lua | 2 | ||||
| -rwxr-xr-x | tests/modules/lib/detect/test.lua | 20 | ||||
| -rw-r--r-- | tests/modules/os/test.lua | 58 | ||||
| -rw-r--r-- | tests/modules/process/test.lua | 56 | ||||
| -rwxr-xr-x | tests/modules/semver/test.lua | 107 | ||||
| -rw-r--r-- | tests/modules/string/test.lua | 60 |
7 files changed, 142 insertions, 189 deletions
diff --git a/tests/modules/devel/git/test.lua b/tests/modules/devel/git/test.lua index ddcfc94b2..0fbae4b1e 100644 --- a/tests/modules/devel/git/test.lua +++ b/tests/modules/devel/git/test.lua @@ -1,21 +1,17 @@ import("devel.git") -function test_asgiturl() - assert(git.asgiturl("http://github.com/a/b") == "https://github.com/a/b.git") - assert(git.asgiturl("http://github.com/a/b/") == "https://github.com/a/b.git") - assert(git.asgiturl("HTTP://github.com//a/b/") == "https://github.com/a/b.git") - assert(git.asgiturl("http://github.com//a/b/s") == nil) - assert(git.asgiturl("https://github.com/a/b") == "https://github.com/a/b.git") - assert(git.asgiturl("https://github.com/a/b.git") == "https://github.com/a/b.git") - assert(git.asgiturl("HTTPS://GITHUB.com/a/b.git.git") == "https://github.com/a/b.git.git") +function test_asgiturl(t) + t:are_equal(git.asgiturl("http://github.com/a/b"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("http://github.com/a/b/"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("HTTP://github.com//a/b/"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("http://github.com//a/b/s"), nil) + t:are_equal(git.asgiturl("https://github.com/a/b"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("https://github.com/a/b.git"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("HTTPS://GITHUB.com/a/b.git.git"), "https://github.com/a/b.git.git") - assert(git.asgiturl("github:a/b") == "https://github.com/a/b.git") - assert(git.asgiturl("github:a/b.git") == "https://github.com/a/b.git.git") - assert(git.asgiturl("GitHub://a/b/") == "https://github.com/a/b.git") - assert(git.asgiturl("github:a/b/c") == nil) -end - -function main() - test_asgiturl() + t:are_equal(git.asgiturl("github:a/b"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("github:a/b.git"), "https://github.com/a/b.git.git") + t:are_equal(git.asgiturl("GitHub://a/b/"), "https://github.com/a/b.git") + t:are_equal(git.asgiturl("github:a/b/c"), nil) end
\ No newline at end of file diff --git a/tests/modules/hello/test.lua b/tests/modules/hello/test.lua index 431a82072..1f4f98a02 100755 --- a/tests/modules/hello/test.lua +++ b/tests/modules/hello/test.lua @@ -1,4 +1,4 @@ -function main() +function test_hello(context) print("hello") end diff --git a/tests/modules/lib/detect/test.lua b/tests/modules/lib/detect/test.lua index c44084ddc..b6937cfaf 100755 --- a/tests/modules/lib/detect/test.lua +++ b/tests/modules/lib/detect/test.lua @@ -1,14 +1,14 @@ import("lib.detect.find_toolname") -function main() - assert(find_toolname("xcrun -sdk macosx clang") == "clang") - assert(find_toolname("xcrun -sdk macosx clang++") == "clangxx") - assert(find_toolname("/usr/bin/arm-linux-gcc") == "gcc") - assert(find_toolname("/usr/bin/arm-linux-g++") == "gxx") - assert(find_toolname("/usr/bin/arm-linux-ar") == "ar") - assert(find_toolname("link.exe -lib") == "link") - assert(find_toolname("arm-android-clang++") == "clangxx") - assert(find_toolname("pkg-config") == "pkg_config") - assert(find_toolname("gcc-5") == "gcc") +function test_find_toolname(t) + t:are_equal(find_toolname("xcrun -sdk macosx clang"), "clang") + t:are_equal(find_toolname("xcrun -sdk macosx clang++"), "clangxx") + t:are_equal(find_toolname("/usr/bin/arm-linux-gcc"), "gcc") + t:are_equal(find_toolname("/usr/bin/arm-linux-g++"), "gxx") + t:are_equal(find_toolname("/usr/bin/arm-linux-ar"), "ar") + t:are_equal(find_toolname("link.exe -lib"), "link") + t:are_equal(find_toolname("arm-android-clang++"), "clangxx") + t:are_equal(find_toolname("pkg-config"), "pkg_config") + t:are_equal(find_toolname("gcc-5"), "gcc") end diff --git a/tests/modules/os/test.lua b/tests/modules/os/test.lua index 681a2ec75..a0ff57ec5 100644 --- a/tests/modules/os/test.lua +++ b/tests/modules/os/test.lua @@ -1,38 +1,62 @@ -function main() +function test_cpdir(t) -- get mclock local tm = os.mclock() -- test cpdir os.mkdir("test1") - assert(os.exists("test1")) + t:require(os.exists("test1")) os.cp("test1","test2") - assert(os.exists("test2")) + t:require(os.exists("test2")) os.rmdir("test1") - assert(not os.exists("test1")) + t:require_not(os.exists("test1")) io.writefile("test2/awd","awd") os.rmdir("test2") - assert(not os.exists("test2")) + t:require_not(os.exists("test2")) + -- assert mclock + t:require(os.mclock() >= tm) +end + +function test_rename(t) + -- get mclock + local tm = os.mclock() -- test rename os.mkdir("test1") - assert(os.exists("test1")) + t:require(os.exists("test1")) os.mv("test1","test2") - assert(not os.exists("test1")) - assert(os.exists("test2")) + t:require_not(os.exists("test1")) + t:require(os.exists("test2")) os.rmdir("test2") - assert(not os.exists("test2")) + t:require_not(os.exists("test2")) + -- assert mclock + t:require(os.mclock() >= tm) +end + +function test_cp_mvdir_into_another_dir(t) + -- get mclock + local tm = os.mclock() -- test cp/mvdir into another dir os.mkdir("test1") os.mkdir("test2") - assert(os.exists("test1") and os.exists("test2")) + t:require(os.exists("test1")) + t:require(os.exists("test2")) os.cp("test1","test2") - assert(os.exists("test2/test1")) + t:require(os.exists("test2/test1")) os.mv("test1","test2/test1") - assert(not os.exists("test1")) - assert(os.exists("test2/test1/test1")) + t:require_not(os.exists("test1")) + t:require(os.exists("test2/test1/test1")) os.rmdir("test2") - assert(not os.exists("test2")) + t:require_not(os.exists("test2")) + -- assert mclock + t:require(os.mclock() >= tm) +end + +function test_setenv(t) + -- get mclock + local tm = os.mclock() -- test setenv os.setenv("__AWD","DWA") - assert(os.getenv("__AWD")=="DWA") + t:are_equal(os.getenv("__AWD"), "DWA") + os.setenv("__AWD","DWA2") + t:are_equal(os.getenv("__AWD"), "DWA2") -- assert mclock - assert(os.mclock()>=tm) -end + t:require(os.mclock() >= tm) +end
\ No newline at end of file diff --git a/tests/modules/process/test.lua b/tests/modules/process/test.lua index 7b5501994..aa57a56cc 100644 --- a/tests/modules/process/test.lua +++ b/tests/modules/process/test.lua @@ -1,52 +1,36 @@ -function main() + +local inftimeout = 5000 + +function test_single_process(t) -- single process test - local inftimeout = 5000 local stdout = os.tmpfile() local stderr = os.tmpfile() for i = 1, 2 do local pro = process.open("echo -n awd", stdout, stderr) process.wait(pro, inftimeout) process.close(pro) - assert(io.readfile(stdout) == "awd") + t:are_equal(io.readfile(stdout), "awd") end +end +function test_hack(t) -- hack test - local ok = try - { - function () - process.wait("awd", inftimeout) - return true - end - } - assert(ok == nil) + t:will_raise(function () + process.wait("awd", inftimeout) + end) - assert(process.close("awd") == nil) + t:require_not(process.close("awd")) - ok = try - { - function () - process.waitlist("awd", inftimeout) - return true - end - } - assert(ok == nil) + t:will_raise(function () + process.waitlist("awd", inftimeout) + end) - ok = try - { - function () - process.waitlist({}, inftimeout) - return true - end - } - assert(ok == nil) + t:will_raise(function () + process.waitlist({}, inftimeout) + end) - ok = try - { - function () - process.waitlist({"awd"}, inftimeout) - return true - end - } - assert(ok == nil) + t:will_raise(function () + process.waitlist({"awd"}, inftimeout) + end) end diff --git a/tests/modules/semver/test.lua b/tests/modules/semver/test.lua index cc1f0c75f..332285df8 100755 --- a/tests/modules/semver/test.lua +++ b/tests/modules/semver/test.lua @@ -2,122 +2,79 @@ import("core.base.semver") -- select version -function _check_semver_select(results, required_ver, versions, tags, branches) +function _check_semver_select(t, results, required_ver, versions, tags, branches) -- select it local version, source = semver.select(required_ver, versions or {}, tags or {}, branches or {}) - if (version.version or version) ~= results[1] or source ~= results[2] then - print("semver.select(\"%s\", {\"%s\"}, {\"%s\"}, {\"%s\"})" - , required_ver - , table.concat(versions or {}, "\", \"") - , table.concat(tags or {}, "\", \"") - , table.concat(branches or {}, "\", \"")) - raise("{\"%s\", \"%s\"} != {\"%s\", \"%s\"}", version.version or version, source or "", results[1] or "", results[2] or "") - end + t:are_equal((version.version or version), results[1]) + t:are_equal(source, results[2]) end -- test select version -function _test_semver_select() +function test_semver_select(t) - _check_semver_select({"1.5.1", "versions"} + _check_semver_select(t, {"1.5.1", "versions"} , ">=1.5.0 <1.6.0" , {"1.4.0", "1.5.0", "1.5.1"}) - _check_semver_select({"1.5.1", "versions"} + _check_semver_select(t, {"1.5.1", "versions"} , "^1.5.0" ,{"1.4.0", "1.5.0", "1.5.1"}) - _check_semver_select({"master", "branches"} + _check_semver_select(t, {"master", "branches"} , "master" , {"1.4.0", "1.5.0", "1.5.1"} , {"v1.2.0", "v1.6.0"} , {"master", "dev"}) - _check_semver_select({"1.5.1", "versions"} + _check_semver_select(t, {"1.5.1", "versions"} , "lastest" , {"1.4.0", "1.5.0", "1.5.1"}) - - print("semver.select: ok!") end -- select version -function _check_semver_satisfies(expected, version, range) +function _check_semver_satisfies(t, expected, version, range) -- select it local result = semver.satisfies(version, range) - if expected ~= result then - print("semver.satisfies(\"%s\", \"%s\")" - , version - , range) - raise("\"%s\" != \"%s\"", expected, result) - end + t:are_equal(result, expected) end -- test satisfies version -function _test_semver_satisfies() +function test_semver_satisfies(t) + + _check_semver_satisfies(t, true, "1.5.1", ">=1.5.0 <1.6.0") + _check_semver_satisfies(t, true, "1.5.1", "^1.5.0") + _check_semver_satisfies(t, true, "1.5.1", "~1.5.0") + _check_semver_satisfies(t, true, "1.6.0", "^1.5.0") - _check_semver_satisfies(true, "1.5.1", ">=1.5.0 <1.6.0") - _check_semver_satisfies(true, "1.5.1", "^1.5.0") + _check_semver_satisfies(t, false, "1.6.1", "~1.5.0") + _check_semver_satisfies(t, false, "2.5.1", "^1.5.0") + _check_semver_satisfies(t, false, "1.4.1", ">=1.5.0 <1.6.0") - print("semver.satisfies: ok!") end -- parse version -function _check_semver_parse(version_str, major, minor, patch, prerelease, build) +function _check_semver_parse(t, version_str, major, minor, patch, prerelease, build) -- create it local version = semver.parse(version_str) - if version.major ~= major then - raise("major: \"%s\" != \"%s\"", version.major or "", major or "") - end - - if version.minor ~= minor then - raise("minor: \"%s\" != \"%s\"", version.minor or "", minor or "") - end + t:are_equal(version.major, major) + t:are_equal(version.minor, minor) + t:are_equal(version.patch, patch) + t:are_equal(version.prerelease, prerelease or {}) + t:are_equal(version.build, build or {}) - if version.patch ~= patch then - raise("patch: \"%s\" != \"%s\"", version.patch or "", patch or "") - end - - if table.concat(version.prerelease or {}, ".") ~= table.concat(prerelease or {}, ".") then - raise("prerelease: \"%s\" != \"%s\"" - , table.concat(version.prerelease or {}, ".") or "" - , table.concat(prerelease or {}, ".") or "") - end - - if table.concat(version.build or {}, ".") ~= table.concat(build or {}, ".") then - raise("build: \"%s\" != \"%s\"" - , table.concat(version.build or {}, ".") or "" - , table.concat(build or {}, ".") or "") - end end -- test parse version -function _test_semver_parse() +function test_semver_parse(t) - _check_semver_parse("1.2.3", 1, 2, 3) - _check_semver_parse("1.2.3-beta", 1, 2, 3, {"beta"}) - _check_semver_parse("1.2.3-beta+77", 1, 2, 3, {"beta"}, {"77"}) - _check_semver_parse("v1.2.3-alpha.1+77", 1, 2, 3, {"alpha", "1"}, {"77"}) - _check_semver_parse("v3.2.1-alpha.1+77.foo", 3, 2, 1, {"alpha", "1"}, {"77", "foo"}) + _check_semver_parse(t, "1.2.3", 1, 2, 3) + _check_semver_parse(t, "1.2.3-beta", 1, 2, 3, {"beta"}) + _check_semver_parse(t, "1.2.3-beta+77", 1, 2, 3, {"beta"}, {77}) + _check_semver_parse(t, "v1.2.3-alpha.1+77", 1, 2, 3, {"alpha", 1}, {77}) + _check_semver_parse(t, "v3.2.1-alpha.1+77.foo", 3, 2, 1, {"alpha", 1}, {77, "foo"}) - print("semver.parse: ok!") -end - --- --- run tests: --- --- $ make test name=semver --- -function main() - - -- test semver - _test_semver_parse() - - -- test semver satisfies - _test_semver_satisfies() - - -- test select version - _test_semver_select() -end +end
\ No newline at end of file diff --git a/tests/modules/string/test.lua b/tests/modules/string/test.lua index 46689dd0f..04ee715ca 100644 --- a/tests/modules/string/test.lua +++ b/tests/modules/string/test.lua @@ -1,48 +1,40 @@ -function assert_array_eq(t1, t2) - assert(table.is_array(t1)) - assert(table.is_array(t2)) - assert(#t1 == #t2, "#t1(%d) != #t2(%d)", #t1, #t2) - for idx, value in ipairs(t1) do - assert(value == t2[idx], "value[%d]: %s != %s", idx, value, t2[idx]) - end -end -function test_endswith() - assert(not ("rc"):endswith("xcadas")) - assert(("aaaccc"):endswith("ccc")) +function test_endswith(t) + t:require(("aaaccc"):endswith("ccc")) + t:require(("aaaccc"):endswith("aaaccc")) + t:require_not(("rc"):endswith("xcadas")) + t:require_not(("aaaccc "):endswith("%s")) end -function test_startswith() - assert(("aaaccc"):startswith("aaa")) +function test_startswith(t) + t:require(("aaaccc"):startswith("aaa")) + t:require(("aaaccc"):startswith("aaaccc")) + t:require_not(("rc"):startswith("xcadas")) + t:require_not((" aaaccc"):startswith("%s")) end -function test_split() +function test_split(t) -- pattern match and ignore empty string - assert_array_eq(("1\n\n2\n3"):split('\n'), {"1", "2", "3"}) - assert_array_eq(("abc123123xyz123abc"):split('123'), {"abc", "xyz", "abc"}) - assert_array_eq(("abc123123xyz123abc"):split('[123]+'), {"abc", "xyz", "abc"}) - + t:are_equal(("1\n\n2\n3"):split('\n'), {"1", "2", "3"}) + t:are_equal(("abc123123xyz123abc"):split('123'), {"abc", "xyz", "abc"}) + t:are_equal(("abc123123xyz123abc"):split('[123]+'), {"abc", "xyz", "abc"}) + -- plain match and ignore empty string - assert_array_eq(("1\n\n2\n3"):split('\n', {plain = true}), {"1", "2", "3"}) - assert_array_eq(("abc123123xyz123abc"):split('123', {plain = true}), {"abc", "xyz", "abc"}) + t:are_equal(("1\n\n2\n3"):split('\n', {plain = true}), {"1", "2", "3"}) + t:are_equal(("abc123123xyz123abc"):split('123', {plain = true}), {"abc", "xyz", "abc"}) -- pattern match and contains empty string - assert_array_eq(("1\n\n2\n3"):split('\n', {strict = true}), {"1", "", "2", "3"}) - assert_array_eq(("abc123123xyz123abc"):split('123', {strict = true}), {"abc", "", "xyz", "abc"}) - assert_array_eq(("abc123123xyz123abc"):split('[123]+', {strict = true}), {"abc", "xyz", "abc"}) + t:are_equal(("1\n\n2\n3"):split('\n', {strict = true}), {"1", "", "2", "3"}) + t:are_equal(("abc123123xyz123abc"):split('123', {strict = true}), {"abc", "", "xyz", "abc"}) + t:are_equal(("abc123123xyz123abc"):split('[123]+', {strict = true}), {"abc", "xyz", "abc"}) -- plain match and contains empty string - assert_array_eq(("1\n\n2\n3"):split('\n', {plain = true, strict = true}), {"1", "", "2", "3"}) - assert_array_eq(("abc123123xyz123abc"):split('123', {plain = true, strict = true}), {"abc", "", "xyz", "abc"}) + t:are_equal(("1\n\n2\n3"):split('\n', {plain = true, strict = true}), {"1", "", "2", "3"}) + t:are_equal(("abc123123xyz123abc"):split('123', {plain = true, strict = true}), {"abc", "", "xyz", "abc"}) -- limit split count - assert_array_eq(("1\n\n2\n3"):split('\n', {limit = 2}), {"1", "2\n3"}) - assert_array_eq(("1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"1", "\n2\n3"}) - assert_array_eq(("1.2.3.4.5"):split('%.', {limit = 3}), {"1", "2", "3.4.5"}) -end - -function main() - test_split() - test_startswith() - test_endswith() + t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2}), {"1", "2\n3"}) + t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"1", "\n2\n3"}) + t:are_equal(("1.2.3.4.5"):split('%.', {limit = 3}), {"1", "2", "3.4.5"}) + t:are_equal(("123.45"):split('%.', {limit = 3}), {"123", "45"}) end |
