Repository: neovim/neovim
File: test/functional/ex_cmds/write_spec.lua (Lua)

Code before:
      write
    ]])
    eq(eval("['content0']"), eval("readfile('test_bkc_file.txt')"))
    eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')"))
  end)

  it("appends FIFO file", function()
    -- mkfifo creates read-only .lnk files on Windows
    if iswin() or eval("executable('mkfifo')") == 0 then
      pending('missing "mkfifo" command')
    end

    local text = "some fifo text from write_spec"
    assert(os.execute("mkfifo test_fifo"))
    insert(text)

    -- Blocks until a consumer reads the FIFO.
    feed_command("write >> test_fifo")

    -- Read the FIFO, this will unblock the :write above.
    local fifo = assert(io.open("test_fifo"))
    eq(text.."\n", fifo:read("*all"))
    fifo:close()
  end)

  it("creates missing parent directories", function()
    command("write ++p test/write/p_opt.txt")
    source([[
      edit test/write/p_opt.txt
      call setline(1, ['line1'])
      write
    ]])
    eq(eval("['line1']"), eval("readfile('test/write/p_opt.txt')"))
  end)

  it('errors out correctly', function()
    if isCI('cirrus') then
      pending('FIXME: cirrus')
    end
    command('let $HOME=""')
    eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~'))
    -- Message from check_overwrite
    if not iswin() then
      eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
        pcall_err(command, 'write .'))
    end
    meths.set_option('writeany', true)
    -- Message from buf_write
    eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .'))
    funcs.mkdir(fname_bak)
    meths.set_option('backupdir', '.')

Review comment (suggestion):
```suggestion
  it("++p creates missing parent directories", function()
```

Code after:
      write
    ]])
    eq(eval("['content0']"), eval("readfile('test_bkc_file.txt')"))
    eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')"))
  end)

  it("appends FIFO file", function()
    -- mkfifo creates read-only .lnk files on Windows
    if iswin() or eval("executable('mkfifo')") == 0 then
      pending('missing "mkfifo" command')
    end

    local text = "some fifo text from write_spec"
    assert(os.execute("mkfifo test_fifo"))
    insert(text)

    -- Blocks until a consumer reads the FIFO.
    feed_command("write >> test_fifo")

    -- Read the FIFO, this will unblock the :write above.
    local fifo = assert(io.open("test_fifo"))
    eq(text.."\n", fifo:read("*all"))
    fifo:close()
  end)

  it("++p creates missing parent directories", function()
    eq(0, eval("filereadable('p_opt.txt')"))
    command("write ++p p_opt.txt")
    eq(1, eval("filereadable('p_opt.txt')"))
    os.remove("p_opt.txt")

    eq(0, eval("filereadable('p_opt.txt')"))
    command("write ++p ./p_opt.txt")
    eq(1, eval("filereadable('p_opt.txt')"))
    os.remove("p_opt.txt")

    eq(0, eval("filereadable('test/write/p_opt.txt')"))
    command("write ++p test/write/p_opt.txt")
    eq(1, eval("filereadable('test/write/p_opt.txt')"))

    eq(('Vim(write):E32: No file name'), pcall_err(command, 'write ++p test_write/'))
    if not iswin() then
      eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
        pcall_err(command, 'write ++p .'))
      eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
        pcall_err(command, 'write ++p ./'))
    end
  end)

  it('errors out correctly', function()
    if isCI('cirrus') then