Commit Graph

622 Commits

Author SHA1 Message Date
Timothy Sample a4cfff0641 Generate the ChangeLog reproducibly.
* build-aux/gitlog-to-changelog-repro.patch: New file.
* Makefile.am (EXTRA_DIST): Add it.
(build-aux/gitlog-to-changelog-repro): New rule.
(gen-ChangeLog): Use 'gitlog-to-changelog-repro'.
(DISTCLEANFILES): Add 'build-aux/gitlog-to-changelog-repro'.
2019-12-09 13:57:15 -05:00
Jan Nieuwenhuizen fda97e32ef Generate reproducible source tarballs.
* Makefile.am (dist-hook): Generate a '.tarball-timestamp' file.
(GZIP_ENV): Override, adding '--no-name'.
(am__tar): Override, adding flags to create reproducible source
tarballs.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-12-09 13:57:15 -05:00
Timothy Sample 82b6769285 Allow running 'make dist' from extracted tarball.
* Makefile (dist-hook): Check for '.git' before generating
'.tarball-manifest'.
2019-12-09 13:57:15 -05:00
Timothy Sample f005b1acbc Generate ChangeLog from Git.
* ChangeLog: Update Git log URL and add a copyright notice.
* Makefile.am (gen-ChangeLog): Use 'gitlog-to-changelog' to generate
the ChangeLog.
2019-12-09 13:57:15 -05:00
Jan Nieuwenhuizen 6f81266e2b gash compat textual-ports: Add put-char.
* gash/compat/textual-ports.scm: Add put-char.
2019-12-09 13:57:15 -05:00
Timothy Sample d905679e9a Initialize the current locale on Guile 2.0.
* gash/gash.scm: Initialize the current locale on Guile 2.0.
2019-12-09 13:57:09 -05:00
Timothy Sample 2d41b4ae5a Allow one-armed 'if-guile-version-below'.
* gash/compat.scm: Allow one-armed 'if-guile-version-below' syntax and
use it to simplify the conditional definitions throughout.
2019-12-09 13:53:55 -05:00
Timothy Sample 4f90afcd3d Use bindings with regular built-ins.
* gash/shell.scm (sh:exec-let): Save and set variables according to
'bindings' before executing a regular built-in.
2019-12-09 13:53:44 -05:00
Timothy Sample 8a440f35f6 Reap every process in a pipeline.
* gash/shell.scm (waitpid/any): New procedure.
(sh:pipeline): Use it to reap every process spawned while executing a
pipeline.
2019-12-09 13:36:41 -05:00
Timothy Sample d600f82f7f Do not leak ports into pipeline processes.
* gash/shell.scm (swap-and-shift-pairs): Remove procedure.
(make-pipes): Remove procedure.
(plumb): Accept another port as an argument and close it when setting
up the child process.
(sh:pipeline): Do not use 'make-pipes' to create all the pipe ports
upfront, but rather create them as needed and give them directly to
'plumb'.
2019-12-09 13:36:41 -05:00
Jan Nieuwenhuizen 7eacf52807 Test executing redirect-created files immediately.
* tests/redirects.org (Files opened for redirect can be executed
immediately): New test.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-12-09 13:36:41 -05:00
Timothy Sample 121d9cb435 Close ports opened for redirects.
* gash/shell.scm (redir->parameter+port): Rename this...
(process-redirect): ...to this, and make it return a list with the
third element being a boolean indicating if the port was opened by us.
(sh:with-redirects): Close ports when the new boolean is set.
2019-12-09 13:36:41 -05:00
Timothy Sample 22205a00a3 Enable 'glob' specification test
* tests/spec/Makefile.am (TESTS): Add 'glob'.
* tests/spec/oil.scm: Patch one of its tests and filter out eleven
others.
2019-12-09 13:36:41 -05:00
Timothy Sample 168f422955 Respect the 'noglob' option.
* gash/word.scm (expand-pathnames): Do not expand pathnames if the
'noglob' option is set.
2019-12-09 13:35:01 -05:00
Timothy Sample 3d3375e066 Fix pathname expansion.
The old implementation had several bugs, prompting this complete
rewrite.

* gash/compat/srfi-43.scm (vector-empty?): New procedure.
* gash/pattern.scm (pattern-null?): New procedure.
* gash/word.scm (qword->pattern-string): New procedure.
(qword->pattern): Rewrite using 'qword->pattern-string'.
(find-files): New procedure.
(expand-pathnames): Rewrite using 'find-files' and add a docstring.
* tests/unit/word.scm: Add tests.
(mock): New syntax.
(make-pure-scandir): New procedure.
(with-mocked-files): New syntax.
2019-12-09 13:23:54 -05:00
Timothy Sample 7687552149 Simplify the 'pattern' data structure.
* gash/pattern.scm (<pattern>): Remove the 'start-anchored?' and
'end-anchored?' fields.
(parse-pattern): Replace the fields with empty parts at the start or
end of the parts list.
(pattern-plain?): Instead of checking the fields, just check the
number of parts.
(pattern-match?, pattern-drop, pattern-drop-right): Do not worry about
the fields, because the empty parts ensure the right thing happens.
2019-12-09 13:04:20 -05:00
Timothy Sample cf6a886f61 Swap semantics of ':+' and '+'.
These were mixed up, with ':+' behaving like '+' and vice versa.

* gash/word.scm (word->qword): Swap implementations of '<sh-ref-and>'
and '<sh-ref-and*>'.
* tests/unit/word.scm: Swap tests.
2019-12-09 13:04:20 -05:00
Timothy Sample 4acbd303a9 Enable 'command-sub' specification test
* tests/spec/Makefile.am (TESTS): Add 'command-sub'.
* tests/spec/oil.scm: Patch four of its tests and filter out another.
2019-12-09 13:04:20 -05:00
Timothy Sample 49ac5e74d3 Fix case statements in '$(...)' substitutions.
* gash/parser.scm (make-parser): Fix the 'pattern!' rule so that it
gets reduced before reading an 'RPAREN' token.
2019-12-09 13:04:20 -05:00
Timothy Sample 66685b6219 Add test for backquoted commands in heredocs.
* tests/unit/parser.scm: Add test.
2019-12-09 13:04:20 -05:00
Timothy Sample 7deaa94bd5 Correctly parse double-quoted backquoted commands.
* gash/lexer.scm (read-backquoted-command): Make the default procedure
accept a 'quoted?' keyword.
(get-backquoted-command): Accept a 'quoted?' keyword and pass it on to
'read-backquoted-command'.
(get-expansion): Accept a 'quoted?' keyword and pass it on to
'get-backquoted-command'.
(get-double-quotation): Set the 'quoted?' keyword when calling
'get-expansion'.
* tests/unit/lexer.scm: Add tests.
* gash/parser.scm (call-with-backquoted-input-port): Accept a
'quoted?' keyword which, if set, adds the double quote character to
the set of escapable characters.
(read-sh/backquoted): Accept a 'quoted?' keyword and pass it on to
'call-with-backquoted-input-port'.
* tests/unit/parser.scm: Add tests.
2019-12-09 13:04:18 -05:00
Timothy Sample 8135e19904 Implement asserting references.
* gash/word.scm (word->qword): Add an implementation for the
'<sh-ref-assert>' and '<sh-ref-assert*>' cases.
* tests/variable-operators.org: New file.
* Makefile.am (FULL_TESTS): Add it.
2019-12-08 12:18:31 -05:00
Timothy Sample 7fee72f5c7 Reset exit status on assignment.
* gash/eval.scm (eval-word): Add 'on-command-substitution' keyword.
(eval-sh): On '<sh-set!>' reset the exit status unless a command
substitution has occurred.
* tests/assignments.org: Add tests.
2019-12-08 12:18:31 -05:00
Timothy Sample 9d98405821 Initialize the 'IFS' variable.
* gash/environment.scm (initial-variables): Initialize 'IFS'.
2019-12-08 12:18:31 -05:00
Timothy Sample d6a582f1bd Only throw for specific special built-in errors.
* gash/shell.scm (sh:exec-let): Do not throw on special built-in
errors.
* gash/built-ins/break.scm (main),
gash/built-ins/continue.scm (main),
gash/built-ins/return.scm (main),
gash/built-ins/shift.scm (main): Throw on error.
2019-12-08 12:18:31 -05:00
Timothy Sample 6990d656bc Make 'trap' handle a numerical action.
* gash/built-ins/utils.scm (string->nonnegative-integer): New procedure.
* gash/built-ins/trap.scm (main): If the first argument is a number,
treat it as if the action were '-'.
2019-12-08 12:18:31 -05:00
Timothy Sample 38001cb76d Fix 'string->positive-integer' docstring typo.
* gash/built-ins/utils.scm (string->positive-integer): Fix a typo in
the docstring.
2019-12-08 12:18:31 -05:00
Timothy Sample 804b6cbe05 Make 'read' handle logical lines.
* gash/built-ins/read.scm (read-logical-line): New procedure.
(main): Use it unless given the '-r' option.
* tests/read.org: Add tests.
2019-12-08 12:18:31 -05:00
Timothy Sample 5fed1b0d87 Make 'read' handle input field splitting.
* gash/built-ins/read.scm (split-fields): New procedure.
(main): Use it to split the input into fields and assign each field to
its corresponding variable.
* tests/read.org: New file.
* Makefile.am (FULL_TESTS): Add it.
2019-12-08 12:18:18 -05:00
Timothy Sample 7a0f4fbae2 Handle nested lists when removing quotes.
* gash/word.scm (remove-quotes): Handle nested lists.
(split-fields) <wedge-apart-quote>: Likewise.
* tests/unit/word.scm: Add test.
2019-11-24 17:40:05 -05:00
Timothy Sample 16ba8ca016 Use temporary assignments when calling functions.
* gash/environment.scm (save-variables-excursion): New procedure.
* gash/shell.scm (sh:exec-let): Use it to set up temporary assignments
during the extent of a function.
* tests/temporary-assignments.org: New file.
* Makefile.am (TESTS): Add it.
2019-11-24 17:13:54 -05:00
Timothy Sample b41ae32106 Delay bracket expression errors in patterns.
* gash/pattern.scm (parse-matching-bracket-expression): Do not
report errors until a full bracket expression has been parsed.
* tests/unit/pattern.scm: Add test.
2019-11-24 17:13:54 -05:00
Timothy Sample 3c7693ece6 Use '(gash compat)' in '(gash built-ins utils)'.
This was omitted from ffe9fc1f47.

* gash/built-ins/utils.scm: Use the '(gash compat)' module.
2019-11-24 17:13:54 -05:00
Timothy Sample 5450e19094 Enable 'var-op-strip' specification test
* tests/spec/Makefile.am (TESTS): Add 'var-op-strip'.
* tests/spec/oil.scm: Patch two of its tests and filter out four
others.
2019-11-24 17:13:54 -05:00
Timothy Sample 1b41a34ce2 Use UTF-8 when processing specification tests.
* tests/spec/oil.scm: Set the encoding on the input and output ports
to UTF-8.
2019-11-24 17:13:54 -05:00
Timothy Sample 5a27fd59cc Implement pattern-based variable operators.
This commit adds an implementation for the '#', '##', '%', and '%%'
variable operators.

* gash/word.scm (word->qword): Add an implementation for the
'<sh-ref-except-min>', '<sh-ref-except-max>', '<sh-ref-skip-min>',
and '<sh-ref-skip-max>' cases.
2019-11-24 17:13:54 -05:00
Timothy Sample 5c1602d5f2 Fix docstring for 'parameter-ref'.
* gash/word.scm (parameter-ref): Fix docstring.
2019-11-24 17:13:54 -05:00
Timothy Sample 223e8d2635 Remove tests for the '/' variable operator.
This is a Bash-specific feature, which means that it is out of scope
for now.

* tests/variable-patterns.org (slash, slash-string,
slash-string-slash): Delete tests.
2019-11-24 17:13:54 -05:00
Timothy Sample e029c4cbab Add pattern dropping procedures.
* gash/pattern.scm (string-contains-part-right): New procedure.
(pattern-drop): New procedure.
(pattern-drop-right): New procedure.
* tests/unit/pattern.scm: Test the dropping procedures.
2019-11-24 17:13:54 -05:00
Timothy Sample 7c8ddd7a43 Use a record type for patterns.
* gash/compat/srfi-43.scm: New file.
* Makefile.am: Add it.
* gash/pattern.scm (<pattern>): New record type.
(parse-part): New procedure.
(parse-pattern): Return a '<pattern>'.
(pattern-plain?, pattern-match?): Accept a '<pattern>'.
(string-starts-with-part, string-ends-with-part,
string-contains-part): Treat 'part' as a vector.
2019-11-24 17:13:54 -05:00
Timothy Sample a009118efb Add tests for 'pattern-plain?'.
* tests/unit/pattern.scm: Add tests for 'pattern-plain?'.
2019-11-24 17:13:54 -05:00
Timothy Sample dd215ee926 Do not test Bash with the specification tests.
* tests/spec/oil.scm: Disable testing Bash in 'spec.sh'.
2019-11-24 17:13:54 -05:00
Timothy Sample 0b49934a0b Remove extra import from 'run-test-suite'.
The '(ice-9 textual-ports)' module is not needed, and using it breaks
the test suite on Guile 2.0.

* tests/run-test-suite.in: Do not use '(ice-9 textual-ports)'.
2019-08-20 11:38:11 -04:00
Timothy Sample 9639f5eff7 Add missing '(gash compat)' import.
This was omitted from ffe9fc1f47.

* gash/shell.scm: Use the '(gash compat)' module.
2019-08-02 20:19:52 -04:00
Timothy Sample fdd835842a Use the 'site' Guile directories when installing.
Thanks to Ludovic Courtès <ludo@gnu.org> for patching this in the Guix
package definition.

* build-aux/guile.am (moddir, ccachedir): Use the 'site' directories.
2019-08-01 09:21:34 -04:00
Timothy Sample d9122d7b68 Use 'sh:exit' for 'errexit'.
* gash/shell.scm (errexit): Exit using 'sh:exit'.
* tests/unit/shell.scm: Make sure exit handlers are called on
'errexit'.
2019-08-01 09:12:35 -04:00
Timothy Sample da9a05d500 Do not use 'with-continuation-barrier'.
It turns out that 'with-continuation-barrier' allows delimited
continuations (i.e., prompts) to get through.

* gash/shell.scm (%subshell): Replace 'with-continuation-barrier' with
'dynamic-wind', making sure to preserve exit statuses that were leaked
through before.
* tests/unit/shell.scm (call-with-temporary-directory): Replace
'with-continuation-barrier' with 'dynamic-wind'.
* tests/spec/oil.scm: Enable previously failing tests.
2019-08-01 09:10:38 -04:00
Timothy Sample 6228064801 Fix top-level 'break', 'continue', and 'return'.
* gash/environment.scm (sh:break, sh:continue, sh:return): Wrap
'abort-to-prompt' with 'false-if-exception'.
* gash/built-ins/break.scm (main): Print warning and continue if
'sh:break' returns.
* gash/built-ins/continue.scm (main): Likewise, but for 'sh:continue'.
* gash/built-ins/return.scm (main): Likewise, but for 'sh:return'.
* tests/functions.org (Top-level return): New test.
* tests/spec/oil.scm: Enable previously failing test.
2019-08-01 09:02:05 -04:00
Timothy Sample 150c6eac53 Handle 'return' errors.
* gash/built-ins/utils.scm (string->exit-status): New procedure.
* gash/built-ins/return.scm (main): Use it to simplify argument
checking; check for too many arguments; and print messages on
errors.
* tests/functions.org (Too many arguments to return): New test.
2019-06-14 20:58:23 -04:00
Timothy Sample ffe9fc1f47 Handle 'break' and 'continue' errors.
* gash/built-ins/utils.scm (string->positive-integer): New function.
* gash/built-ins/break.scm (main): Use it to simplify argument
checking; check for too many arguments; and print messages on errors.
* gash/built-ins/continue.scm (main): Ditto.
* gash/shell.scm (sh:exec-let): Throw an error if a special built-in
fails.
* tests/spec/oil.scm: Enable and adjust previously failing tests.
2019-06-14 20:46:57 -04:00