diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-02-02 16:34:02 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-02-02 18:58:20 +0200 |
commit | 80c09a9ac632be5e172424a73665497d44ab675a (patch) | |
tree | a44301553561bbf2deac64cf974f517c2ce0d6b9 | |
parent | edf38541a5d038bea74052cb169c9017ed7a2e8a (diff) | |
download | xenv-80c09a9ac632be5e172424a73665497d44ab675a.tar.gz xenv-80c09a9ac632be5e172424a73665497d44ab675a.tar.bz2 |
Add testsuite
* Makefile: Build the testsuite.
Support make install and make check.
* xenv.l: Emit synclines in ECHO.
Preprocessor statements are removed completely, together with
the trailing newline.
* t/comment.at: New file.
* t/ifdef.at: New file.
* t/ifndef.at: New file.
* t/ifnset.at: New file.
* t/ifset.at: New file.
* t/quote.at: New file.
* t/set.at: New file.
* t/testsuite.at: New file.
* t/unset.at: New file.
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | Makefile | 123 | ||||
-rw-r--r-- | atlocal | 1 | ||||
-rw-r--r-- | t/asndfl.at | 69 | ||||
-rw-r--r-- | t/braces.at | 54 | ||||
-rw-r--r-- | t/comment.at | 39 | ||||
-rw-r--r-- | t/errmsg.at | 86 | ||||
-rw-r--r-- | t/error.at | 86 | ||||
-rw-r--r-- | t/ifdef.at | 60 | ||||
-rw-r--r-- | t/ifndef.at | 60 | ||||
-rw-r--r-- | t/ifnset.at | 60 | ||||
-rw-r--r-- | t/ifset.at | 60 | ||||
-rw-r--r-- | t/quote.at | 54 | ||||
-rw-r--r-- | t/set.at | 34 | ||||
-rw-r--r-- | t/simple.at | 54 | ||||
-rw-r--r-- | t/ternary.at | 57 | ||||
-rw-r--r-- | t/testsuite.at | 34 | ||||
-rw-r--r-- | t/unset.at | 30 | ||||
-rw-r--r-- | t/usealt.at | 50 | ||||
-rw-r--r-- | t/usedfl.at | 57 | ||||
-rw-r--r-- | xenv.l | 68 |
21 files changed, 1114 insertions, 29 deletions
@@ -1,8 +1,13 @@ +.gdbinit xenv lex.yy.c tmp .emacs* *~ \#*# -*.tar +*.tar.gz core +testsuite +testsuite.dir +testsuite.log +package.m4 @@ -1,9 +1,41 @@ +# This file is part of xenv +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + CPPFLAGS = CFLAGS = -ggdb -Wall LEXFLAGS = -F -PACKAGE = xenv -VERSION = 0.1 +# Installation prefix +PREFIX = /usr/local +MANDIR = $(PREFIX)/share/man +BINDIR = $(PREFIX)/bin +MAN1DIR = $(MANDIR)/man1 + +# Install program. Use cp(1) if not available. +INSTALL = install +# Program to make a directory hierarchy. +MKHIER = install -d + +# ############################# +# Building the program. +# ############################# +PACKAGE_NAME = xenv +PACKAGE_VERSION = 0.1 +PACKAGE_TARNAME = $(PACKAGE_NAME)-$(PACKAGE_VERSION) +PACKAGE_BUGREPORT = gray@gnu.org xenv: lex.yy.c $(CC) -oxenv $(CPPFLAGS) $(CFLAGS) lex.yy.c @@ -11,12 +43,91 @@ lex.yy.c: xenv.l flex $(LEXFLAGS) xenv.l clean: rm -f xenv lex.yy.c -DISTNAME = $(PACKAGE)-$(VERSION) -DISTDIR = $(DISTNAME) + +check: xenv testsuite + @./testsuite + +# ############################### +# Building the testsuite. +# ############################### +AUTOM4TE = autom4te +AUTOTEST = $(AUTOM4TE) --language=autotest + +TESTSUITE_AT = \ + t/testsuite.at \ + t/asndfl.at\ + t/braces.at\ + t/comment.at\ + t/errmsg.at\ + t/error.at\ + t/ifdef.at\ + t/ifndef.at\ + t/ifnset.at\ + t/ifset.at\ + t/quote.at\ + t/set.at\ + t/simple.at\ + t/ternary.at\ + t/unset.at\ + t/usealt.at\ + t/usedfl.at + +package.m4: Makefile + { \ + echo '# Signature of the current package.'; \ + echo 'm4_define([AT_PACKAGE_NAME], [$(PACKAGE_NAME)])'; \ + echo 'm4_define([AT_PACKAGE_TARNAME], [$(PACKAGE_TARNAME)])'; \ + echo 'm4_define([AT_PACKAGE_VERSION], [$(PACKAGE_VERSION)])'; \ + echo 'm4_define([AT_PACKAGE_STRING], [$(PACKAGE_TARNAME)])'; \ + echo 'm4_define([AT_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])'; \ + } > package.m4 + +EXTRA_DIST = atlocal package.m4 + +testsuite: package.m4 $(TESTSUITE_AT) + $(AUTOTEST) -I . -I t t/testsuite.at -o testsuite + +# ############################### +# Install +# ############################### + +install: install-bin install-man + +install-bin: xenv + $(MKHIER) $(DESTDIR)$(BINDIR) + $(INSTALL) xenv $(DESTDIR)$(BINDIR) + +install-man: + $(MKHIER) $(DESTDIR)$(MAN1DIR) + $(INSTALL) xenv.1 $(DESTDIR)$(MAN1DIR) + +# ############################### +# Distribution +# ############################### +DISTDIR = $(PACKAGE_TARNAME) +DISTFILES = xenv.l xenv.1 Makefile lex.yy.c testsuite + distdir: lex.yy.c rm -rf $(DISTDIR) mkdir $(DISTDIR) - cp xenv.l xenv.1 Makefile lex.yy.c $(DISTDIR) + cp $(DISTFILES) $(EXTRA_DIST) $(DISTDIR) + mkdir $(DISTDIR)/t + cp $(TESTSUITE_AT) $(DISTDIR)/t + dist: distdir - tar cf $(DISTNAME).tar $(DISTDIR) + tar zcf $(PACKAGE_TARNAME).tar.gz $(DISTDIR) rm -rf $(DISTDIR) + + +distcheck: dist + tar xfz $(PACKAGE_TARNAME).tar.gz + if $(MAKE) -C $(DISTDIR) $(DISTCHECKFLAGS) check; then \ + text="$(DISTDIR).tar.gz ready for distribution"; \ + echo "$$text" | sed s/./=/g; \ + echo "$$text"; \ + echo "$$text" | sed s/./=/g; \ + rm -rf $(DISTDIR); \ + else \ + exit 2; \ + fi + @@ -0,0 +1 @@ +PATH=.:$PATH
\ No newline at end of file diff --git a/t/asndfl.at b/t/asndfl.at new file mode 100644 index 0000000..0b8baa9 --- /dev/null +++ b/t/asndfl.at @@ -0,0 +1,69 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Assign default values]) + +AT_DATA([input], +[Lorem ipsum ${OBJ=dolor} sit am${EX:=et}, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore $EX ${OBJ}e magna aliqua. +]) + +AT_CHECK([ +unset OBJ EX +xenv input +], +[0], +[Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +]) + +AT_CHECK([ +OBJ=nitor +export OBJ +unset EX +xenv input +], +[0], +[Lorem ipsum nitor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et nitore magna aliqua. +]) + +AT_CHECK([ +OBJ=nitor +export OBJ +EX=abunt +export EX +xenv input +], +[0], +[Lorem ipsum nitor sit amabunt, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore abunt nitore magna aliqua. +]) + +AT_CHECK([ +OBJ= +export OBJ +EX= +export EX +xenv input +], +[0], +[Lorem ipsum sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et e magna aliqua. +]) + + +AT_CLEANUP diff --git a/t/braces.at b/t/braces.at new file mode 100644 index 0000000..58de00a --- /dev/null +++ b/t/braces.at @@ -0,0 +1,54 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Brace expansion]) +AT_DATA([input], +[foo is ${X_FOO}, bar is ${X_BAR}. +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv input], +[0], +[foo is , bar is . +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv -u input], +[65], +[foo is , bar is . +], +[input:1: variable X_FOO not defined +input:1: variable X_BAR not defined +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv -ur input], +[65], +[foo is ${X_FOO}, bar is ${X_BAR}. +], +[input:1: variable X_FOO not defined +input:1: variable X_BAR not defined +]) +AT_CHECK([ +X_FOO=baz X_BAR=qux xenv -u input], +[0], +[foo is baz, bar is qux. +]) + +AT_CLEANUP
\ No newline at end of file diff --git a/t/comment.at b/t/comment.at new file mode 100644 index 0000000..b92f7f1 --- /dev/null +++ b/t/comment.at @@ -0,0 +1,39 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Comments]) +AT_DATA([input], +[${* Comment statements are ignored *} +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +${* Comments can be multi-line, +as shown here. Variable references in comments (${X:?}) are ignored. +Newline character following the comment is retained. *} +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. +]) +AT_CHECK([unset X +xenv input +], +[0], +[ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, + +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. +]) +AT_CLEANUP diff --git a/t/errmsg.at b/t/errmsg.at new file mode 100644 index 0000000..15ff22f --- /dev/null +++ b/t/errmsg.at @@ -0,0 +1,86 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Display Custom Error if Null or Unset]) + +AT_DATA([input], +[Ut enim ad minim ${V1?Should have set V1}, quis nostrud exercitation ullamco +${V2:?Should have set V2 to a non-empty value} nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +V1=veniam +V2=laboris +export V1 V2 +xenv input +], +[0], +[Ut enim ad minim veniam, quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +V1= +V2=laboris +export V1 V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +unset V1 +V2=laboris +export V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +], +[input:1: Should have set V1 +]) + +AT_CHECK([ +unset V1 V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco + nisi ut aliquip ex ea commodo consequat. +], +[input:1: Should have set V1 +input:2: Should have set V2 to a non-empty value +]) + +AT_CHECK([ +unset V1 +V2= +export V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco + nisi ut aliquip ex ea commodo consequat. +], +[input:1: Should have set V1 +input:2: Should have set V2 to a non-empty value +]) + +AT_CLEANUP + diff --git a/t/error.at b/t/error.at new file mode 100644 index 0000000..378d76b --- /dev/null +++ b/t/error.at @@ -0,0 +1,86 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Display Error if Null or Unset]) + +AT_DATA([input], +[Ut enim ad minim ${V1?}, quis nostrud exercitation ullamco +${V2:?} nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +V1=veniam +V2=laboris +export V1 V2 +xenv input +], +[0], +[Ut enim ad minim veniam, quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +V1= +V2=laboris +export V1 V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +]) + +AT_CHECK([ +unset V1 +V2=laboris +export V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea commodo consequat. +], +[input:1: variable V1 not set +]) + +AT_CHECK([ +unset V1 V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco + nisi ut aliquip ex ea commodo consequat. +], +[input:1: variable V1 not set +input:2: variable V2 null or not set +]) + +AT_CHECK([ +unset V1 +V2= +export V2 +xenv input +], +[0], +[Ut enim ad minim , quis nostrud exercitation ullamco + nisi ut aliquip ex ea commodo consequat. +], +[input:1: variable V1 not set +input:2: variable V2 null or not set +]) + +AT_CLEANUP + diff --git a/t/ifdef.at b/t/ifdef.at new file mode 100644 index 0000000..97dd888 --- /dev/null +++ b/t/ifdef.at @@ -0,0 +1,60 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([$$ifdef]) +AT_DATA([input], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +$$ifdef X +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +$$else +$$ ifdef Y +... +$$ endif +$$ endif +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X Y +xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X +Y= xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +... +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([ +X= xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CLEANUP diff --git a/t/ifndef.at b/t/ifndef.at new file mode 100644 index 0000000..a4cd384 --- /dev/null +++ b/t/ifndef.at @@ -0,0 +1,60 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([$$ifndef]) +AT_DATA([input], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +$$ifndef X +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +$$else +$$ ifndef Y +... +$$ endif +$$ endif +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X Y +xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset Y +X= xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +... +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([ +X= Y= xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CLEANUP diff --git a/t/ifnset.at b/t/ifnset.at new file mode 100644 index 0000000..bcfe5a7 --- /dev/null +++ b/t/ifnset.at @@ -0,0 +1,60 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([$$ifnset]) +AT_DATA([input], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +$$ifnset X +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +$$else +$$ ifnset Y +... +$$ endif +$$ endif +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X Y +xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset Y +X=1 xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +... +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([ +X=1 Y=1 xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CLEANUP diff --git a/t/ifset.at b/t/ifset.at new file mode 100644 index 0000000..f7f7ac1 --- /dev/null +++ b/t/ifset.at @@ -0,0 +1,60 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([$$ifset]) +AT_DATA([input], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +$$ifset X +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +$$else +$$ ifset Y +... +$$ endif +$$ endif +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X Y +xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([unset X +Y=1 xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +... +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CHECK([ +X=1 xenv input +], +[0], +[Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat +cupidatat non proident, sunt in culpa qui officia deserunt mollit +anim id est laborum. +]) + +AT_CLEANUP diff --git a/t/quote.at b/t/quote.at new file mode 100644 index 0000000..a10d09f --- /dev/null +++ b/t/quote.at @@ -0,0 +1,54 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Quoting]) +AT_DATA([input],[ +Anything appearing between \$( and ) is quoted. +Quoted $(text keeps track of (balanced ()) parentheses to +find the right closing) one. +$(Unbalanced parentheses can be quoted like that: \). + +No variable expansion occurs within quotes, e.g.: $X. + +Preprocessed statements and comments are retained as well: + + $$ifset X + + ${* comment *} + +After closing parenthesis, normal preprocessing is restored:) $X. +]) + +AT_CHECK([X=TEXT xenv input], +[0], +[ +Anything appearing between $( and ) is quoted. +Quoted text keeps track of (balanced ()) parentheses to +find the right closing one. +Unbalanced parentheses can be quoted like that: ). + +No variable expansion occurs within quotes, e.g.: $X. + +Preprocessed statements and comments are retained as well: + + $$ifset X + + ${* comment *} + +After closing parenthesis, normal preprocessing is restored: TEXT. +]) + +AT_CLEANUP diff --git a/t/set.at b/t/set.at new file mode 100644 index 0000000..0c840e4 --- /dev/null +++ b/t/set.at @@ -0,0 +1,34 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([$$set]) +AT_CHECK([ +AT_DATA([input], +[$$set X + $$ set Y "string \"nested string\" test" + +X is ${X+set (value '$X')} +Y is ${Y+set (value '$Y')} +]) +unset X Y +xenv input +], +[0], +[ +X is set (value '') +Y is set (value 'string "nested string" test') +]) +AT_CLEANUP diff --git a/t/simple.at b/t/simple.at new file mode 100644 index 0000000..74be3de --- /dev/null +++ b/t/simple.at @@ -0,0 +1,54 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Simple expansion]) +AT_DATA([input], +[foo is $X_FOO, bar is $X_BAR. +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv input], +[0], +[foo is , bar is . +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv -u input], +[65], +[foo is , bar is . +], +[input:1: variable X_FOO not defined +input:1: variable X_BAR not defined +]) +AT_CHECK([ +unset X_FOO +unset X_BAR +xenv -ur input], +[65], +[foo is $X_FOO, bar is $X_BAR. +], +[input:1: variable X_FOO not defined +input:1: variable X_BAR not defined +]) +AT_CHECK([ +X_FOO=baz X_BAR=qux xenv -u input], +[0], +[foo is baz, bar is qux. +]) + +AT_CLEANUP
\ No newline at end of file diff --git a/t/ternary.at b/t/ternary.at new file mode 100644 index 0000000..03888ef --- /dev/null +++ b/t/ternary.at @@ -0,0 +1,57 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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 xenv. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([Ternary operator]) +AT_DATA([input], +[Lorem ipsum ${OBJ|dolor|fulgor} sit amet, ${GBR:|consectetur|obliviscetur} adipiscing elit, +sed ${LIM:||do }eiusmod tempor ${ALT:|incididunt} ut labore et dolore magna aliqua. +]) + +AT_CHECK([ +unset OBJ GBR LIM ALT +xenv input +], +[0], +[Lorem ipsum fulgor sit amet, obliviscetur adipiscing elit, +sed do eiusmod tempor ut labore et dolore magna aliqua. +]) +AT_CHECK([ +OBJ= +GBR= +LIM= +ALT= +export OBJ GBR LIM ALT +xenv input +], +[0], +[Lorem ipsum dolor sit amet, obliviscetur adipiscing elit, +sed do eiusmod tempor ut labore et dolore magna aliqua. +]) + +AT_CHECK([ +OBJ=1 +GBR=1 +LIM=1 +ALT=1 +export OBJ GBR LIM ALT +xenv input +], +[0], +[Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed eiusmod tempor incididunt ut labore et dolore magna aliqua. +]) + +AT_CLEANUP diff --git a/t/testsuite.at b/t/testsuite.at new file mode 100644 index 0000000..ecdb3fe --- /dev/null +++ b/t/testsuite.at @@ -0,0 +1,34 @@ +# This file is part of xenv -*- autotest -*- +# Copyright (C) 2021 Sergey Poznyakoff +# +# Xenv 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 3 of the License, or (at your +# option) any later version. +# +# Xenv 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. |