From: Richard W.M. Jones Date: Sat, 11 Jan 2020 11:57:08 +0000 (+0000) Subject: tests: More basic tests. X-Git-Tag: v'0.2'~42 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=bf91d4bb90c84d360609ffb30a68cf8adb5b1448;p=goals.git tests: More basic tests. --- diff --git a/tests/00-all-fail.gl b/tests/00-all-fail.gl new file mode 100644 index 0000000..8fc6132 --- /dev/null +++ b/tests/00-all-fail.gl @@ -0,0 +1,21 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# If the all goal exits with an error, so should goals. + +goal all = { exit 1 } diff --git a/tests/00-all-fail.sh b/tests/00-all-fail.sh new file mode 100755 index 0000000..86fda73 --- /dev/null +++ b/tests/00-all-fail.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# This is expected to return an error, and as long as it does this +# script is successful. Don't print the error message because that +# will confuse everyone. +if goals -f 00-all-fail.gl 2>/dev/null; then + exit 1 +else + exit 0 +fi diff --git a/tests/00-empty-code.gl b/tests/00-empty-code.gl new file mode 100644 index 0000000..5141550 --- /dev/null +++ b/tests/00-empty-code.gl @@ -0,0 +1,27 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Empty goals, functions, etc. should do nothing and not fail. + +let deps = empty_function () + +goal all = : empty_goal, deps + +goal empty_goal = { } + +function empty_function () returning strings = { } diff --git a/tests/00-empty-code.sh b/tests/00-empty-code.sh new file mode 100755 index 0000000..d22ee4f --- /dev/null +++ b/tests/00-empty-code.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +goals -f 00-empty-code.gl diff --git a/tests/00-insert-var.gl b/tests/00-insert-var.gl new file mode 100644 index 0000000..465836d --- /dev/null +++ b/tests/00-insert-var.gl @@ -0,0 +1,28 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test various substitutions/insertions to construct a final variable. + +let r = "R" +let i = "I" +let g = "G" +let h = "H" +let t = "T" +let var = "%r%i%g%h%t" + +goal all = { echo %var } diff --git a/tests/00-insert-var.sh b/tests/00-insert-var.sh new file mode 100755 index 0000000..e5b371d --- /dev/null +++ b/tests/00-insert-var.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +goals -f 00-insert-var.gl > 00-insert-var.out +test "$(cat 00-insert-var.out)" = "RIGHT" + +rm 00-insert-var.out diff --git a/tests/00-override-goal.gl b/tests/00-override-goal.gl new file mode 100644 index 0000000..a624901 --- /dev/null +++ b/tests/00-override-goal.gl @@ -0,0 +1,25 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Overriding a goal should use the last definition. + +goal all = { exit 1 } +goal all = { exit 1 } + +# Only this goal should run. +goal all = { } diff --git a/tests/00-override-goal.sh b/tests/00-override-goal.sh new file mode 100755 index 0000000..b8e500f --- /dev/null +++ b/tests/00-override-goal.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +goals -f 00-override-goal.gl diff --git a/tests/00-override-var.gl b/tests/00-override-var.gl new file mode 100644 index 0000000..9b3ad1f --- /dev/null +++ b/tests/00-override-var.gl @@ -0,0 +1,25 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Overriding a variable should use the last definition. + +let var = "WRONG" +let var = "WRONG" +let var = "RIGHT" + +goal all = { echo %var } diff --git a/tests/00-override-var.sh b/tests/00-override-var.sh new file mode 100755 index 0000000..8b5c47b --- /dev/null +++ b/tests/00-override-var.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +goals -f 00-override-var.gl > 00-override-var.out +test "$(cat 00-override-var.out)" = "RIGHT" + +rm 00-override-var.out diff --git a/tests/00-variable-not-found.gl b/tests/00-variable-not-found.gl new file mode 100644 index 0000000..b2ed4d2 --- /dev/null +++ b/tests/00-variable-not-found.gl @@ -0,0 +1,23 @@ +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Bad subsitution should give an error. + +let var = "%bad" + +goal all = { echo %var } diff --git a/tests/00-variable-not-found.sh b/tests/00-variable-not-found.sh new file mode 100755 index 0000000..c0cb899 --- /dev/null +++ b/tests/00-variable-not-found.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Goals test. +# Copyright (C) 2020 Richard W.M. Jones +# Copyright (C) 2020 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# This is expected to return an error, and as long as it does this +# script is successful. Don't print the error message because that +# will confuse everyone. +if goals -f 00-variable-not-found.gl 2>/dev/null; then + exit 1 +else + exit 0 +fi