PageRenderTime 65ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/error.k

https://bitbucket.org/qyqx/klisp
K | 72 lines | 61 code | 11 blank | 0 comment | 1 complexity | 4bd0934333e3736e917cd10912f29c0c MD5 | raw file
  1. ;; check.k & test-helpers.k should be loaded
  2. ;;
  3. ;; Tests of error handling applicatives.
  4. ;;
  5. ;; XXX error
  6. ;;
  7. ($check-error (error "test"))
  8. ;; XXX error-object? error-object-message error-object-irritants
  9. ;;
  10. ($let*
  11. ( (capture-error-object
  12. ($lambda (proc)
  13. (guard-dynamic-extent
  14. ()
  15. proc
  16. (list (list error-continuation
  17. ($lambda (obj divert)
  18. (apply divert obj)))))))
  19. (e1 (capture-error-object ($lambda () (error "a"))))
  20. (e2 (capture-error-object ($lambda () (error "b" 1 2 3))))
  21. (e3 (capture-error-object ($lambda () (error))))
  22. (e4 (capture-error-object ($lambda () (error 1)))))
  23. ($check-predicate (error-object? e1 e2 e3))
  24. ($check-not-predicate (error-object? ""))
  25. ($check-not-predicate (error-object? #f))
  26. ($check-not-predicate (error-object? ()))
  27. ($check-not-predicate (error-object? 0))
  28. ($check equal? (error-object-message e1) "a")
  29. ($check equal? (error-object-message e2) "b")
  30. ($check-error (error-object-message))
  31. ($check-error (error-object-message e1 e2))
  32. ($check-error (error-object-message "not an error object"))
  33. ($check equal? (error-object-irritants e1) ())
  34. ($check equal? (error-object-irritants e2) (list 1 2 3))
  35. ($check equal? (error-object-irritants e3) ())
  36. ;; error now uses the standard binding constructs from kghelper
  37. ;; for now they don't encapsulate any data in the error, but
  38. ;; they will in the future
  39. ;; ($check equal? (error-object-irritants e4) (list 1))
  40. ($check-error (error-object-irritants))
  41. ($check-error (error-object-irritants e1 e2))
  42. ($check-error (error-object-irritants "not an error object")))
  43. ;; XXX system-error-continuation
  44. ($check-predicate (continuation? system-error-continuation))
  45. ($let*
  46. ( (catch-system-error
  47. ($lambda (proc)
  48. (guard-dynamic-extent
  49. ()
  50. proc
  51. (list (list system-error-continuation
  52. ($lambda (obj divert)
  53. ($let
  54. ( ( ((service code message errno) . tail)
  55. (error-object-irritants obj)))
  56. (apply divert (list* service code tail))))))))))
  57. ($check equal?
  58. (catch-system-error
  59. ($lambda ()
  60. (rename-file "nonexistent-file-name" "other-file-name")))
  61. (list "rename" "ENOENT" "nonexistent-file-name" "other-file-name")))