From a88d6f2eeba2b3355c33fac6d736cf6086342f47 Mon Sep 17 00:00:00 2001 From: hisham Date: Wed, 1 Apr 2009 17:11:57 +0000 Subject: Import latest revision from CVS at luaforge.net git-svn-id: http://luarocks.org/svn/luarocks/trunk@1 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- test/run_tests.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_deps.lua | 67 +++++++++++++++++++++++++++++++++++++++++++++ test/test_require.lua | 25 +++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100755 test/run_tests.sh create mode 100644 test/test_deps.lua create mode 100755 test/test_require.lua (limited to 'test') diff --git a/test/run_tests.sh b/test/run_tests.sh new file mode 100755 index 00000000..aa06854f --- /dev/null +++ b/test/run_tests.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +if [ -e ./run_tests.sh ] +then + cd ../src +elif [ -d src ] +then + cd src +elif ! [ -d luarocks ] +then + echo "Go to the src directory and run this." + exit 1 +fi + +if [ ! -d ../rocks ] +then + echo "Downloading entire rocks repository for tests" + cd .. + wget -r -nH -np -R"index.*" http://luarocks.luaforge.net/rocks/ + cd src +fi + +rocks=( + `ls ../rocks/*.rockspec | grep -v luacom` + `ls ../rocks/*.src.rock | grep -v luacom` +) + +bin/luarocks-admin make-manifest ../rocks || exit 1 + +[ "$1" ] && rocks=("$1") + +TRY() { + "$@" || { + echo "Failed running: $@" + exit 1 + } +} + +list_search() { + bin/luarocks list $name | grep $version +} + +for rock in "${rocks[@]}" +do + base=`basename $rock` + baserockspec=`basename $rock .rockspec` + basesrcrock=`basename $rock .src.rock` + if [ "$base" != "$baserockspec" ] + then + base=$baserockspec + name=`echo $base | sed 's/\(.*\)-[^-]*-[^-]*$/\1/'` + version=`echo $base | sed 's/.*-\([^-]*-[^-]*\)$/\1/'` + TRY bin/luarocks pack $rock + TRY bin/luarocks build $base.src.rock + TRY rm $base.src.rock + else + base=$basesrcrock + name=`echo $base | sed 's/\(.*\)-[^-]*-[^-]*$/\1/'` + version=`echo $base | sed 's/.*-\([^-]*-[^-]*\)$/\1/'` + TRY bin/luarocks build $rock + fi + TRY bin/luarocks pack $name $version + TRY bin/luarocks install $base.*.rock + TRY rm $base.*.rock + TRY list_search $name $version + bin/luarocks remove $name $version + # TODO: differentiate between error and dependency block. +done + +if bin/luarocks install nonexistant | grep "No results" +then echo "OK, got expected error." +else exit 1 +fi + +TRY ../test/test_deps.lua +TRY ../test/test_require.lua diff --git a/test/test_deps.lua b/test/test_deps.lua new file mode 100644 index 00000000..7236273c --- /dev/null +++ b/test/test_deps.lua @@ -0,0 +1,67 @@ +#!/usr/bin/env lua + +deps = require "luarocks.deps" + +print(deps.show_dep(deps.parse_dep("lfs 2.1.9pre5"), true)) +print(deps.show_dep(deps.parse_dep("cgilua cvs-2"), true)) +print(deps.show_dep(deps.parse_dep("foobar 0.0.1beta"), true)) +print(deps.show_dep(deps.parse_dep("foobar 0.0.1a"), true)) + +print(deps.show_dep(deps.parse_dep("foobar 1"), true)) +print(deps.show_dep(deps.parse_dep("foobar 2.0"), true)) +print(deps.show_dep(deps.parse_dep("foobar 3.5a4"), true)) +print(deps.show_dep(deps.parse_dep("foobar 1.1pre2"), true)) +print(deps.show_dep(deps.parse_dep("foobar 2.0-beta3"), true)) +print(deps.show_dep(deps.parse_dep("foobar 5.3"), true)) +print(deps.show_dep(deps.parse_dep("foobar 3.5rc2"), true)) +print(deps.show_dep(deps.parse_dep("foobar 4.19p"), true)) + +print() +comparisons = { +-- first second eq le + {"Vista", "XP", false, true}, + {"XP", "3.1", false, true}, + {"1.0", "1.0", true, false}, + {"2.2.10", "2.2-10", false, false}, + {"2.2", "2.2-10", true, false}, + {"1.0beta1", "1.0rc3", false, true}, + {"2.0beta3", "2.0", false, true}, + {"2.0beta", "2.0beta2", false, true}, + {"2.0beta4", "2.0beta3", false, false}, + {"2.1alpha1", "2.0beta1", false, false}, + {"1.5p3", "1.5.1", false, true}, + {"1.1.3", "1.1.3a", false, true}, + {"1.5a100", "1.5b1", false, true}, + {"2.0alpha100", "2.0beta1", false, true}, + {"2.0.0beta3", "2.0beta2", false, false}, + {"2.0-1", "2.0-2", false, true}, + {"2.0-2", "2.0-1", false, false}, + --[[ + -- Corner cases I don't wish to handle by now. + {"2.0.0beta2", "2.0beta2", true, true}, + {"2.0.0beta2", "2.0beta3", false, true}, + ]] +} + +local v1, v2 + +err = false + +function result(test, expected) + if test == expected then + print(test, "OK") + else + print(test, "ERROR", deps.show_version(v1, true), deps.show_version(v2, true)) + err = true + end +end + +for _, c in ipairs(comparisons) do + v1, v2 = deps.parse_version(c[1]), deps.parse_version(c[2]) + print(c[1].." == "..c[2].." ?") + result(v1 == v2, c[3]) + print(c[1].." < "..c[2].." ?") + result(v1 < v2, c[4]) +end + +if err then os.exit(1) end diff --git a/test/test_require.lua b/test/test_require.lua new file mode 100755 index 00000000..2a652d29 --- /dev/null +++ b/test/test_require.lua @@ -0,0 +1,25 @@ +#!/usr/bin/env lua + +local luarocks = require("luarocks.require") + +luarocks.set_context("cgilua", "cvs-2") + +print(package.path) + +print(package.cpath) + +local socket = require("socket") +if not socket then os.exit(1) end +print(socket, socket._VERSION) + +local socket2 = require("socket") +if not socket2 then os.exit(1) end +print(socket2, socket2._VERSION) + +local mime = require("mime") +if not mime then os.exit(1) end +print(mime, mime._VERSION) + +local socket = require("lfs") +if not lfs then os.exit(1) end +print(lfs, lfs._VERSION) -- cgit v1.2.3-55-g6feb