Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post-command-hook related tests #1093

Merged
merged 1 commit into from
Jan 19, 2016
Merged

Add post-command-hook related tests #1093

merged 1 commit into from
Jan 19, 2016

Conversation

geraldus
Copy link
Contributor

Don't merge yet, I opened this to see coverage stats first.

@gracjan I've spent few hour trying to make it record changes to flag during ert running test. I have tried command-execute, call-interactively, execute-kbd-macro, and changing modes but flag remains empty all the time. Can you help me with this?

(haskell-utils-async-watch-changes)
(should (null haskell-utils-async-post-command-flag))
;; now invoke some commands and test flag value
(insert "Hello World!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use:

      (execute-kbd-macro "DEF")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives error during test:

(end-of-buffer)

(goto-char (point-min)) does not help.

@gracjan
Copy link
Contributor

gracjan commented Jan 18, 2016

Summary:

  • insert does not execute post command hooks, but execute-kbd-macro does
  • a temporary switch-to-buffer is needed for execute-kbd-macro to work correctly
  • there are nice functional functions in cl-lib.el

@geraldus
Copy link
Contributor Author

Well, I've found only two ways to cover haskell-utils-async-update-post-command-flag — to call it directly or explicitly run post-command hooks (run-hooks 'post-command-hook). The former is just a coverage hack and in fact tests nothing, while latter looks good. I guess post-command hooks wont't run until test body is not fully evaluated (there is only one command stored in flag-variable — ert). This method also work with with-temp-buffer.

@geraldus
Copy link
Contributor Author

Don't merge this yet. Let's merge test-utils first, then I'll rebase code (I guess this will be needed, won't it?).

@geraldus
Copy link
Contributor Author

Ok, this is almost total coverage! 📈

Any good ideas about last uncovered function?

@gracjan
Copy link
Contributor

gracjan commented Jan 19, 2016

Use with-temp-switch-to-buffer in place of with-temp-buffer and then use execute-kbd-macro in place of (run-hooks 'post-command-hook). It will work correctly.

@geraldus geraldus closed this Jan 19, 2016
@geraldus geraldus reopened this Jan 19, 2016
@geraldus geraldus closed this Jan 19, 2016
@geraldus geraldus reopened this Jan 19, 2016
@geraldus
Copy link
Contributor Author

Well, we cannot test interactive stuff in batch mode, because:

Part of batch mode is that it does not have interactivity ...

An important caveat to this approach is that it will not work in a batch-mode emacs session, presumably because emacs doesn't process keyboard input at all in batch mode.

So, I'll remove last commit in few minutes, @gracjan can we have some special init file to run Emacs not in batch mode (if this is even possible on Travis), then run interactive tests with mentioned hacks [1] and finally exit Emacs?
By the way, can't contact you via IRC whole day, you're constantly online, does this mean that you receives all messages I sent you?

gracjan added a commit that referenced this pull request Jan 19, 2016
Add post-command-hook related tests
@gracjan gracjan merged commit f314243 into haskell:master Jan 19, 2016
@gracjan
Copy link
Contributor

gracjan commented Jan 19, 2016

@geraldus: I never saw your interactive commit so I do not know what you are talking about.

I have some IRC bouncer set up, so I get all messages when I get back to computer.

@geraldus
Copy link
Contributor Author

@gracjan wow, Evil's registers prevented me from loosing it comletely:

(ert-deftest read-directory-name ()
  "Test `haskell-utils-read-directory-name'.
This is very simple test, it just runs
  `haskell-utils-read-directory-name' function with default
  directory set to home dir.  Since we have no clue about
  evnironment the only way to test this function will be simulate
  RET keypress and compare result to home folder path - the
  latter should be a prexif ot former."
  (let* ((home (getenv "HOME"))
         (unread-command-events (listify-key-sequence (kbd "RET G-g")))
         (result (haskell-utils-read-directory-name "> " home)))
    (should (string-prefix-p home result))))

while this woks fine in non-batch mode, Travis builds are failing after 10 minutes timeout.

@gracjan
Copy link
Contributor

gracjan commented Jan 19, 2016

In the particular case of haskell-utils-read-directory-name it is better to use el-mock to mock read-directory-name. We have el-mock dependency already so this is good.

@geraldus
Copy link
Contributor Author

@gracjan I didn't catch how to use it, can you explain a bit?

@gracjan
Copy link
Contributor

gracjan commented Jan 20, 2016

Example of el-mock usage:

    (mocklet (((haskell-session-name "dummy-session") => "dumses1"))
                     (haskell-process-compute-process-log-and-command "dummy-session" 'ghci)))

So in our situation this would be something like:

    (mocklet (((read-directory-name ? ? ?) => ?))
                     (should (equal "xxx" (haskell-utils-read-directory-name ? ? ?)))

@geraldus
Copy link
Contributor Author

@gracjan let me not to be greedy in this respect and leave this final piece to you (or someone else). Sorry, I need some time to learn that mocklets and have some other tasks to do in nearest time 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants