vixie-time.scm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ;;;; vixie-time.scm -- tests for (mcron vixie-time) module
  2. ;;; Copyright © 2018 Mathieu Lirzin <mthl@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Mcron.
  5. ;;;
  6. ;;; GNU Mcron is free software: you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; GNU Mcron is distributed in the hope that it will be useful,
  12. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>.
  18. (use-modules (srfi srfi-1)
  19. (srfi srfi-64)
  20. (mcron vixie-time))
  21. (setenv "TZ" "UTC0")
  22. (test-begin "vixie-time")
  23. (define (times-equal spec times proc)
  24. (test-equal spec
  25. (cdr times)
  26. (fold-right (λ (val acc)
  27. (cons (proc val) acc))
  28. '()
  29. (drop-right times 1))))
  30. (times-equal
  31. "every minute"
  32. '(0 60 120 180 240 300 360 420)
  33. (parse-vixie-time "* * * * *"))
  34. (times-equal
  35. "every hour"
  36. (list 0
  37. 3600
  38. (* 2 3600)
  39. (* 3 3600)
  40. (* 4 3600)
  41. (* 5 3600)
  42. (* 6 3600)
  43. (* 7 3600))
  44. (parse-vixie-time "0 * * * *"))
  45. (times-equal
  46. "every day"
  47. (list 0
  48. (* 24 3600)
  49. (* 2 24 3600)
  50. (* 3 24 3600)
  51. (* 4 24 3600)
  52. (* 5 24 3600)
  53. (* 6 24 3600)
  54. (* 7 24 3600))
  55. (parse-vixie-time "0 0 * * *"))
  56. (times-equal
  57. "every month"
  58. (list 0
  59. (* 31 86400) ;jan
  60. (* (+ 31 28) 86400) ;fev
  61. (* (+ 31 28 31) 86400) ;mar
  62. (* (+ 31 28 31 30) 86400) ;avr
  63. (* (+ 31 28 31 30 31) 86400) ;may
  64. (* (+ 31 28 31 30 31 30) 86400) ;jun
  65. (* (+ 31 28 31 30 31 30 31) 86400)) ;july
  66. (parse-vixie-time "0 0 1 * *"))
  67. (times-equal
  68. "every year"
  69. (list 0
  70. (* 365 86400) ;1971
  71. (* 2 365 86400) ;1972 (leap)
  72. (* (+ (* 2 365) 366) 86400) ;1973
  73. (* (+ (* 3 365) 366) 86400) ;1974
  74. (* (+ (* 4 365) 366) 86400) ;1975
  75. (* (+ (* 5 365) 366) 86400) ;1976 (leap)
  76. (* (+ (* 5 365) (* 2 366)) 86400)) ;1977
  77. (parse-vixie-time "0 0 1 0 *"))
  78. (times-equal
  79. "30 4 1,15 * 5"
  80. (list 0
  81. (+ (* 4 3600) 1800)
  82. (+ (* 28 3600) 1800)
  83. (+ (* 8 86400) (* 4 3600) 1800)
  84. (+ (* 13 86400) (* 28 3600) 1800)
  85. (+ (* 15 86400) (* 4 3600) 1800)
  86. (+ (* 532 3600) 1800))
  87. (parse-vixie-time "30 4 1,15 * 5"))
  88. ;;;
  89. ;;; Errors
  90. ;;;
  91. ;; FIXME: infinite loop
  92. ;; (test-error "month 0" #t
  93. ;; (let ((p (parse-vixie-time "0 0 0 * *")))
  94. ;; (p 1234)))
  95. (test-error
  96. "not enough fields"
  97. 'mcron-error
  98. (parse-vixie-time "1 2 3 4"))
  99. (test-error
  100. "too many fields"
  101. 'mcron-error
  102. (parse-vixie-time "1 2 3 4 5 6"))
  103. (test-end)