emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/with-simulated-input b030953ca0 050/134: Fix a bug with ac


From: ELPA Syncer
Subject: [nongnu] elpa/with-simulated-input b030953ca0 050/134: Fix a bug with actually-wait, and add tests for it
Date: Mon, 10 Jan 2022 23:00:04 -0500 (EST)

branch: elpa/with-simulated-input
commit b030953ca053c7372d2f5a415813f5cc3a66b89a
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>

    Fix a bug with actually-wait, and add tests for it
---
 tests/test-with-simulated-input.el | 16 ++++++++++++++++
 with-simulated-input.el            | 16 +++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tests/test-with-simulated-input.el 
b/tests/test-with-simulated-input.el
index 9f32fc0c24..e509661e7f 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -216,6 +216,22 @@
     (wsi-simulate-idle-time)
     (expect 'idle-canary :to-have-been-called))
 
+  (it "should simulate the appropriate value for `(current-idle-time)'")
+
+  (it "should actually wait the specified time when `actually-wait' is non-nil"
+    (spy-on 'sleep-for :and-call-through)
+    (run-with-idle-timer 0.01 nil 'idle-canary)
+    (run-with-idle-timer 0.02 nil 'idle-canary)
+    (run-with-idle-timer 0.03 nil 'idle-canary)
+    (run-with-idle-timer 0.04 nil 'idle-canary)
+    ;; These shouldn't get called
+    (run-with-idle-timer 1 nil 'idle-canary)
+    (run-with-idle-timer 2 nil 'idle-canary)
+    (run-with-idle-timer 3 nil 'idle-canary)
+    (wsi-simulate-idle-time 0.05 t)
+    (expect 'idle-canary :to-have-been-called-times 4)
+    (expect 'sleep-for :to-have-been-called-times 5))
+
   (describe "used within `with-simulated-input'"
     (it "should allow idle timers to trigger during simulated input"
       (run-with-idle-timer 500 nil 'insert "world")
diff --git a/with-simulated-input.el b/with-simulated-input.el
index 663c6a02d7..dc2c837df6 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -255,7 +255,14 @@ in `progn'."
          (error "Reached end of simulated input while evaluating body")
        result)))
 
-(defvar wsi-simulated-idle-time nil)
+(defvar wsi-simulated-idle-time nil
+  "The current simulated idle time.
+
+While simulating idle time using `wsi-simulated-idle-time', this
+variable will always be set to the amount of idle time that has
+been simulated so far. For example, if an idle time is set to run
+every 5 seconds while idle, then on its first run, this will be
+set to 5 seconds, then 10 seconds the next time, and so on.")
 
 (defun current-idle-time@simulate-idle-time (orig-fun &rest args)
   "Return the faked value while simulating idle time.
@@ -311,9 +318,12 @@ add other idle timers."
    ;; timers to the list, and picking up at the same list position
    ;; would ignore those new timers.
    for next-timer = (car (cl-member-if-not
-                          (lambda (timer) (memq timer already-run-timers))
+                          (lambda (timer)
+                            (and (memq timer already-run-timers)))
                           timer-idle-list))
-   while next-timer
+   ;; Stop if we reach the end of the idle timer list, or if the next
+   ;; timer's idle time is greater than SECS
+   while (and next-timer (time-less-p (timer--time next-timer) stop-time))
    for previous-idle-time = wsi-simulated-idle-time
    if (time-less-p wsi-simulated-idle-time
                    (timer--time next-timer))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]