Commit graph

29 commits

Author SHA1 Message Date
Dale Mellor
cbce8eb293
Incorporate and use command-line-processor proposed for Guile core
Since the elimination of the C wrapping around mcron and all the
executable scripts, a weakness in Guile's (ice-9 getopt-long) module
means that the command 'mcron -s crontab.scm' does not currently
work.  A replacement for the getopt-long module, as well as a
higher-level 'command-line-processor' facility, have been pushed to
the Guile upstream developers and are awaiting approval and
incorporation.  In the meantime, those modules are temporarily
incorporated here into the mcron package, and the code is modified
to use those local versions.

 * Makefile.am: install two new Guile modules
 * src/{cron,crontab,mcron}.in: use local command-line-processor module
 * src/mcron/command-line-processor.scm: new module
 * src/mcron/getopt-long.scm: new module
 * tests/schedule{,-2}.sh: clarify tests of -s, --schedule options
2022-07-07 22:19:06 +01:00
Mathieu Lirzin
5fd0ccde5a
tests: Check (mcron vixie-specification)
* tests/vixie-specification.scm: New file.
* Makefile.am (TESTS): Register it.
2022-07-07 16:56:54 +01:00
Dale Mellor
e2ecb8045b
Give mcron --log option to turn logging on.
This makes the behaviour backwards compatible with all previous uses of mcron.

* src/mcron/base.scm: establish %do-logging parameter and act on it
* src/mcron/scripts/mcron.scm: set %do-logging according to command line
* tests/base.scm: some tests require %do-logging to be set
2022-07-07 16:51:31 +01:00
Maxim Cournoyer
a7a456cd6f
base: Annotate output with job information.
Before this change, it was difficult to discern which job emitted which
output, as there was no information connecting the job to the output it
produced.  This change rectifies that by annotating each line output by
cron/mcron with a prefix that contains a timestamp and the job name.  It also
reports about when the job runs and whether it completed successfully or
failed.  It was initially suggested here: <https://issues.guix.gnu.org/36510>.

Thanks to the fine people from the #guile libera.chat IRC channel for
providing ideas and help; this change would not have been possible without
them!

* src/mcron/base.scm (install-suspendable-ports!): Install suspendable ports.
(%date-format, %log-format): New parameters.
(validate-date-format, validate-log-format): New procedures.
(<job-data>): New record.
(run-job): Update doc.  Redirect stdout and stderr to a pipe.  Return a
<job-data> instance containing the input port and other information about the
job.  Output job status messages.
(process-output): New procedure.
(child-cleanup): Add docstring.  Use positive logic.  Call 'process-output'
one last time after a child process is collected.
(run-job-loop): Add a CHILDREN-DATA variable to the loop.  Provide the open
file descriptors of the children ports to select*, and collect their output
when they trigger select.
* tests/base.scm ("run-job: basic"): Adjust and fix indentation.
(dummy-job/capture-output): New procedure.
("run-job, output"): New test.
("validate-date-format, valid", "validate-date-format, invalid")
("validate-log-format, valid", "validate-log-format, invalid")
("run-job, output with custom format", "run-job, failure")
("run-job, failure in shell action"): New tests.
* src/mcron/scripts/cron.scm (show-help): Document new options.
(%options) [log-format, date-format]: New options.
(main): Parameterize the main loop with the new parameter options (or their
default values when not provided); move exception handling elsewhere (see
below).
* src/mcron/scripts/mcron.scm: Likewise.
* src/cron.in: Install error handler here.
* src/mcron.in: Likewise.
* doc/mcron.texi: Document new cron and mcron options, as well as new
(mcron base) APIs.
* tests/basic.sh: Test the new options.

Suggested-by: Robert Vollmert <rob@vllmrt.net>
2022-07-07 09:06:57 +01:00
Dale Mellor
1eedf3b6d2 project: banish need for C compiler
This patch gets rid of the thin veneer that we currently have around the three
executables.  This was done for historical reasons (circa 2003 Guile couldnʼt
deal with process signals and forks).  In fact these problems were fixed many
moons ago, and there is now no need for it.  The project becomes 100% Guile!

Many files are affected; interested coders should use the GIT repository to
understand the details of all the changes.
2020-04-20 17:03:25 +00:00
Dale Mellor
4a05a2e861 test: demonstrate incorrect -s option on mcron program
The option is supposed to be able to take an optional argument, but if the
argument is not supplied (should default to 8) then the test, rather than
failing, is skipped with a friendly message in the log file.  The proper fix
will come with an upstream patch to GNU Guile, and a future version of Mcron.

* tests/schedule-2.sh: new test, new file
* Makefile.am: make sure to run the new test file
2020-04-20 16:49:05 +00:00
Dale Mellor
ad6e4e5505 test: Demonstration of failure to open local file.
The mcron program goes looking for files specified on the command
line in Guile's module path, inevitably resulting in failure to load
said file.  Running 'make check' will show at least one failure.

* tests/basic.sh: Added new test.
2020-04-20 16:49:05 +00:00
Dale Mellor
a8d938c4ed test: make date tests reliable, i.e. independent of current time
Some of the date tests depend both on the particular time of day and year at
which the test is run, and also on the state of daylight-savings adjustments.
(At the present time on my system there are four failing tests, but YMMV.)
This patch puts all the tests to UTC time in the C locale, making the results
consistent.  *All* items in the test suite should be passing once again.

* tests/job-schedule.scm: Fix up the environment before running the tests.
2020-04-20 16:48:52 +00:00
Mathieu Lirzin
9187aeb78f
tests: Add "tests/vixie-time.scm"
* tests/vixie-time.scm: New test.
* Makefile.am (TESTS): Add it.
2018-04-08 16:07:16 +02:00
Mathieu Lirzin
d8127a386c
utils: Check 'show-version' and 'show-package-information'
* tests/utils.scm ("show-package-information")
("show-version"): New tests.
2018-03-27 03:30:04 +02:00
Mathieu Lirzin
8ab0465d92
job-specifier: Check 'job'
* tests/job-specifier.scm ("job: procedure timeproc")
("job: list timeproc", "job: string timeproc", "job: list action")
("job: invalid string timeproc", "job: invalid timeproc")
("job: procedure action", "job: string action")
("job: user name"): New tests.
2018-03-27 03:17:36 +02:00
Mathieu Lirzin
15fa52f7ec
job-specifier: Box 'configuration-user' global variable
* src/mcron/job-specifier.scm (configuration-user): Box it using
SRFI-111 to be explicit about the mutability of this object.
(job): Adapt.
(set-configuration-user): Adapt and use 'get-user'.
* tests/job-specifier.scm ("set-configuration-user: passwd entry")
("set-configuration-user: invalid uid", "set-configuration-user: uid")
("set-configuration-user: invalid spec")
("set-configuration-user: name"): New tests.
2018-03-27 03:13:14 +02:00
Mathieu Lirzin
56f85cfd8a
job-specifier: Check 'next-...' procedures
* tests/job-specifier.scm ("next-year", "next-month", "next-day")
("next-hour", "next-minute", "next-second"): New tests.
("next-hour-from"): Remove.
2018-03-27 03:13:13 +02:00
Mathieu Lirzin
95fb914025
base: Check how child processes are handled
* tests/base.scm ("run-job: basic"): Check the number of children too.
("child-cleanup: one", "update-number-children!: set value"): New tests.
2018-03-26 21:11:16 +02:00
Mathieu Lirzin
f71b0b8310
job-specifier: Adapt 'bump-time' to 'next-...-from' procedures
This is a follow-up to commit 913e3c65e4.

Since 'next-...-from' procedures now uses an '#:optional' argument
instead of a dotted optional arguments list, 'bump-time' doesn't need to
unwrap VALUE-LIST anymore.

* src/mcron/job-specifier.scm (bump-time): Pass VALUE-LIST directly to
'%find-best-next'.
* tests/job-specifier.scm ("next-hour-from"): New test.
* NEWS: Update.

Reported-by: Ludovic Courtès <ludo@gnu.org>
2018-03-26 17:51:11 +02:00
Mathieu Lirzin
fad58ca8c2
job-specifier: Preserve '%find-best-next' arguments exactness
The behavior of the 'min' procedure which converts its parameters to
inexact numbers when at least one of them is inexact was causing
'%find-best-next' to always return real numbers.

* src/mcron/job-specifier.scm (%find-best-next): Preserve the exactness
of numbers in NEXT-LIST.
* tests/job-specifier.scm ("%find-best-next: exact"): New test.

Reported-by: Ludovic Courtès <ludo@gnu.org>
2018-03-26 17:20:26 +02:00
Mathieu Lirzin
4d636af876
utils: Check 'mcron-error'
* tests/utils.scm ("mcron-error: exit code", "mcron-error: output")
("mcron-error: output no-exit", "mcron-error: only stderr"): New tests.
2018-03-25 03:01:45 +02:00
Mathieu Lirzin
5af999fb20
tests: Add "tests/utils.scm"
* tests/utils.scm: New test.
* Makefile.am (TESTS): Add it.
2018-03-25 00:38:26 +01:00
Mathieu Lirzin
0159423d15
tests: Remove unused schedule stubs
* tests/base.scm ("number-children: init")
("update-number-children!: 1+", "update-number-children!: 1-"): Remove
'let' form defining the schedule stub.
2018-03-24 21:13:51 +01:00
Mathieu Lirzin
b8cbf635cc
environment: Check configuration environment
* tests/environment.scm ("current-environment-mods-copy: empty")
("current-environment-mods: init", "append-environment-mods: basic")
("append-environment-mods: twice", "clear-environment-mods: effect")
("current-environment-mods-copy: basic"): New tests.
2018-03-24 20:32:13 +01:00
Mathieu Lirzin
d1e0d2a8f7
base: Check 'run-job'
* tests/base.scm ("run-job: basic"): New test.
2018-03-24 15:32:56 +01:00
Mathieu Lirzin
526ce502e5
base: Box 'number-children'
* src/mcron/base.scm (number-children): Box it using SRFI-111 to be
explicit about the mutability of this object.
(update-number-children!): New procedure.
(run-job, child-cleanup): Use it.
* tests/base.scm ("update-number-children!: 1+")
("number-children: init", "update-number-children!: 1-"): New tests.
2018-03-24 14:03:54 +01:00
Mathieu Lirzin
6583e83d16
tests: Add "tests/base.scm"
* tests/base.scm: New test.
* Makefile.am (TESTS): Add it.
2018-03-24 01:18:21 +01:00
Mathieu Lirzin
f908c5395c
utils: Use 'scandir' instead of custom 'for-each-file'
* src/mcron/utils.scm (for-each-file): Delete.
* src/mcron/scripts/cron.scm (process-files-in-system-directory): Use
'scandir' which has the benefit of being deterministic.
* src/mcron/scripts/mcron.scm (process-files-in-user-directory):
Likewise.
* tests/schedule.sh: Update expected output which is now more reliable.
* NEWS: Update.

Suggested-by: Ludovic Courtès <ludo@gnu.org>
2018-03-20 19:27:10 +01:00
Mathieu Lirzin
09e452b62a
tests: Set timezone in "schedule.sh"
Previously the test environment was implicitly expecting the current
timezone to be UTC+1.

* tests/schedule.sh: Set TZ environment variable to 'UTC0'.
Update expected result.

Reported-by: Ludovic Courtès <ludo@gnu.org>
2018-03-20 19:25:28 +01:00
Mathieu Lirzin
2b9b54b729
tests: Add 'schedule.sh'
* tests/schedule.sh: New test.
* Makefile.am (TESTS): Add it.
* src/mcron/job-specifier.scm (configuration-time): Use
SOURCE_DATE_EPOCH for reproducible tests.
2018-03-16 21:41:52 +01:00
Mathieu Lirzin
c285d36ab2
tests: Add 'basic.sh'
* tests/init.sh: New test framework from Gnulib.
* tests/basic.sh: New test.
* Makefile.am (TESTS): Add it.
(TEST_EXTENSIONS): Add '.sh'.
(SH_LOG_COMPILER): Use 'pre-inst-env'.
(EXTRA_DIST): Add 'tests/init.sh'.
* build-aux/pre-inst-env.in: export $srcdir for shell tests.
2017-09-28 18:48:49 +02:00
Mathieu Lirzin
e9fde01d27
environment: modify-environment: Add tests.
* tests/environment.scm: New test.
* Makefile.am (TESTS): Add it.
2016-12-01 00:15:55 +01:00
Mathieu Lirzin
9d173e23bc
job-specifier: range: Add tests.
* build-aux/test-driver.scm: New script.
* configure.ac (AC_REQUIRE_AUX_FILE): Add it.
* tests/job-specifier.scm: New test.
* Makefile.am (TEST_EXTENSIONS, AM_TESTS_ENVIRONMENT, SCM_LOG_DRIVER)
(TESTS): New variables.
(EXTRA_DIST): Update.
* .gitignore: Likewise.
2016-12-01 00:15:55 +01:00