diff options
| author | ruki <[email protected]> | 2017-05-20 00:42:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-20 00:42:05 +0800 |
| commit | ce27b8d4dfae08a01f473e7a5cfbb94f6e79c967 (patch) | |
| tree | 76cb0f63a16787f920c3dac016ad7b6f5c2d7250 /tests | |
| parent | c6876982657c8bf65b7e2a05fc1206b3aacc0ff8 (diff) | |
improve test script
Diffstat (limited to 'tests')
23 files changed, 250 insertions, 187 deletions
diff --git a/tests/build.lua b/tests/build.lua new file mode 100644 index 000000000..918b00133 --- /dev/null +++ b/tests/build.lua @@ -0,0 +1,30 @@ +-- main entry +function main(argv) + + -- generic? + os.exec("xmake m -b") + os.exec("xmake f -c") + os.exec("xmake") + os.exec("xmake p") + os.exec("xmake c") + os.exec("xmake f -m release") + os.exec("xmake -r -a -v --backtrace") + os.exec("xmake f --mode=debug --verbose --backtrace") + os.exec("xmake --rebuild --all --verbose --backtrace") + os.exec("xmake p --verbose --backtrace") + os.exec("xmake c --verbose --backtrace") + os.exec("xmake m -e buildtest") + os.exec("xmake m -l") + os.exec("xmake f --cc=gcc --cxx=g++") + os.exec("xmake m buildtest") + os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") + os.exec("xmake m buildtest") + os.exec("xmake m -d buildtest") + + -- test iphoneos? + if argv and argv.iphoneos then + if os.host() == "macosx" then + os.exec("xmake m package -p iphoneos") + end + end +end diff --git a/tests/modules/hello/test.lua b/tests/modules/hello/test.lua new file mode 100755 index 000000000..431a82072 --- /dev/null +++ b/tests/modules/hello/test.lua @@ -0,0 +1,4 @@ +function main() + + print("hello") +end diff --git a/tests/modules/ping.lua b/tests/modules/ping.lua deleted file mode 100755 index 53ee0132a..000000000 --- a/tests/modules/ping.lua +++ /dev/null @@ -1,13 +0,0 @@ --- imports -import("core.tool.ping") - --- --- run tests: --- --- $ xmake l ./tests/modules/ping.lua --- -function main() - - -- send ping - table.dump(ping.send("www.tboox.org", "www.xmake.io", "www.github.com", "www.google.com", "unknown.invalid")) -end diff --git a/tests/modules/semver.lua b/tests/modules/semver.lua deleted file mode 100755 index 0db0c1718..000000000 --- a/tests/modules/semver.lua +++ /dev/null @@ -1,94 +0,0 @@ --- imports -import("core.base.semver") - --- select version -function _check_semver_select(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 -end - --- test select version -function _test_semver_select() - - _check_semver_select({"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"} - , "^1.5.0" - ,{"1.4.0", "1.5.0", "1.5.1"}) - - _check_semver_select({"master", "branches"} - , "master" - , {"1.4.0", "1.5.0", "1.5.1"} - , {"v1.2.0", "v1.6.0"} - , {"master", "dev"}) - - print("semver.select: ok!") -end - --- parse version -function _check_semver_parse(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 - - 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() - - _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"}) - - print("semver.parse: ok!") -end - --- --- run tests: --- --- $ xmake l ./tests/modules/semver.lua --- -function main() - - -- test semver - _test_semver_parse() - - -- test select version - _test_semver_select() -end diff --git a/tests/projects/console_c++/test.lua b/tests/projects/console_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/console_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/console_c/test.lua b/tests/projects/console_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/console_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/console_dlang/test.lua b/tests/projects/console_dlang/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_dlang/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_go/test.lua b/tests/projects/console_go/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_go/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_objc++/test.lua b/tests/projects/console_objc++/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_objc++/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/console_objc/test.lua b/tests/projects/console_objc/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_objc/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/console_rust/test.lua b/tests/projects/console_rust/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_rust/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_swift/test.lua b/tests/projects/console_swift/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_swift/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/merge_object/test.lua b/tests/projects/merge_object/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/merge_object/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/merge_static_library/test.lua b/tests/projects/merge_static_library/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/merge_static_library/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_c++/test.lua b/tests/projects/shared_library_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/shared_library_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_c/test.lua b/tests/projects/shared_library_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/shared_library_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_dlang/test.lua b/tests/projects/shared_library_dlang/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/shared_library_dlang/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/static_library_c++/test.lua b/tests/projects/static_library_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/static_library_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/static_library_c/test.lua b/tests/projects/static_library_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/static_library_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/static_library_go/test.lua b/tests/projects/static_library_go/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/static_library_go/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/static_library_rust/test.lua b/tests/projects/static_library_rust/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/static_library_rust/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/test.lua b/tests/test.lua new file mode 100644 index 000000000..2f67ba416 --- /dev/null +++ b/tests/test.lua @@ -0,0 +1,45 @@ +-- imports +import("core.project.task") + +-- run test with the given name +function _run_test(name) + + -- find the test script + for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", name, "test.lua"))) do + + -- trace + print("testing %s ...", script) + + -- enter script directory + os.cd(path.directory(script)) + + -- run test + task.run("lua", {script = path.filename(script)}) + break + end +end + +-- main entry +function main(name) + + -- run the given test + if name then + return _run_test(name) + end + + -- run all tests + for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", "test.lua"))) do + + -- trace + print("testing %s ...", script) + + -- enter script directory + local oldir = os.cd(path.directory(script)) + + -- run test + task.run("lua", {script = path.filename(script)}) + + -- leave script directory + os.cd(oldir) + end +end diff --git a/tests/tests b/tests/tests deleted file mode 100755 index 32b8f9bd8..000000000 --- a/tests/tests +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -verbose=$1 -host=linux -if [ `uname` = "Darwin" ] || [ `uname | egrep -i darwin` ]; then - host=macosx -fi - -function exec() -{ - echo $1 - eval $1 $verbose - if [ $? -ne 0 ] - then exit -1 - fi - echo "" -} - -function build() -{ - # echo project name - echo "build $1" - - # build - exec "xmake f -c -P $1" - exec "xmake -P $1" - exec "xmake p -P $1" -} - -function build_for_iphoenos() -{ - # echo project name - echo "build $1" - - # package all archs for iphoneos - exec "xmake m -P $1 package -p iphoneos" -} - -# build for c -build "./tests/projects/console_c" -build "./tests/projects/static_library_c" -build "./tests/projects/shared_library_c" - -# build for c++ -build "./tests/projects/console_c++" -build "./tests/projects/static_library_c++" -build "./tests/projects/shared_library_c++" - -# merge object -build "./tests/projects/merge_object" - -# merge static library -build "./tests/projects/merge_static_library" - -# build for macosx -if [ $host = "macosx" ]; then - - # build for objc/c++ - build "./tests/projects/console_objc" - build "./tests/projects/console_objc++" - build_for_iphoenos "./tests/projects/console_objc" - build_for_iphoenos "./tests/projects/console_objc++" - - # build for swift - build "./tests/projects/console_swift" - build_for_iphoenos "./tests/projects/console_swift" - - # build for go - build "./tests/projects/console_go" - build "./tests/projects/static_library_go" - - # build for dlang - build "./tests/projects/console_dlang" - build "./tests/projects/static_library_dlang" - - # build for rust - build "./tests/projects/console_rust" - build "./tests/projects/static_library_rust" -fi - |
