junegunn / vader.vim

A simple Vimscript test framework
589 stars 40 forks source link

Can Vader test if new file is opened properly? #219

Open srasku opened 3 years ago

srasku commented 3 years ago

I am writing a plugin which should allow opening files by hitting return on them similar to what Fugitive does. Is this a testable scenario?

I wrote some tests for Fugitive but the one to test opening a file doesn't work. It works if I test it manually. Am I doing something wrong?

Note that the contents I am expecting won't match but I'm getting no contents at all. This is my Vader output.

Starting Vader: 1 suite(s), 7 case(s)
  Starting Vader: /Users/Stephen/.vim/bundle/vim-fugitive/test/fugitive-Gstatus.vader
    (1/7) [EXECUTE] Git on unmodified repo
    (1/7) [ EXPECT] empty file
    (2/7) [EXECUTE] Git with added file
      > Check that foo exists
    (2/7) [ EXPECT] added file
    (3/7) [EXECUTE] Git with removed file
    (3/7) [ EXPECT] removed file
    (4/7) [EXECUTE] Git with missing file
    (4/7) [ EXPECT] missing file
    (5/7) [EXECUTE] Git with untracked file
    (5/7) [ EXPECT] untracked file
    (6/7) [     DO] select foo
    (6/7) [   THEN] foo opens
      > Filetype should not be "fugitive"
    (6/7) [   THEN] (X) '[Vader-workbench]' should be equal to 'foo'
    (6/7) [ EXPECT] (X) foo contents
      - Expected:
          foo should not be empty
      - Got:

    (7/7) [EXECUTE] cleanup
    (7/7) [   THEN] directory has been removed
      > Checking whether vader-clone directory has been deleted.
  Success/Total: 6/7
Success/Total: 6/7 (assertions: 10/11)
Elapsed time: 1.755594 sec.
alerque commented 2 years ago

Interesting question. I just ran into an issue with an ftdetect loader and couldn't figure out how to write a test for it. If anybody finds a working example of testing if opening a file resulted in the right file type I'd love to see it.

dkearns commented 2 years ago

func Test_detection()