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

Code before:
        [[
        let g:foobar = 42
      ]]
      )
      screen = Screen.new(500, 8)
    end)

    after_each(function()
      screen:detach()
      os.remove('Xfile')
      n.rmdir('Xdir')
      n.rmdir(xstate)
    end)

    it('regular file', function()
      screen:set_default_attr_ids({
        [1] = { bold = true, foreground = Screen.colors.Blue1 },
        [2] = { bold = true, reverse = true },
        [3] = { bold = true, foreground = Screen.colors.SeaGreen },
        [4] = { reverse = true },
      })

      local cwd = fn.getcwd()
      local msg = cwd
        .. pathsep
        .. 'Xfile is not trusted. To enable this exrc file, (v)iew it and run `:trust`.'
      if #msg >= screen._width then
        pending('path too long')
        return
      end

      -- Need to use feed_command instead of exec_lua because of the confirmation prompt
      feed_command([[lua vim.secure.read('Xfile')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xfile'){MATCH: +}|
        {3:]] .. msg .. [[}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
      ]])
      feed('d')
      screen:expect([[
        ^{MATCH: +}|
        {1:~{MATCH: +}}|*6
        {MATCH: +}|
      ]])

      local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust'))
      eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust))
      eq(vim.NIL, exec_lua([[return vim.secure.read('Xfile')]]))

Review comment (suggestion):
Let's adjust this to:
```suggestion
        .. 'Xfile is not trusted. To enable it, choose (v)iew then run `:trust`.'
```

Code after:
        [[
        let g:foobar = 42
      ]]
      )
      screen = Screen.new(500, 8)
    end)

    after_each(function()
      screen:detach()
      os.remove('Xfile')
      n.rmdir('Xdir')
      n.rmdir(xstate)
    end)

    it('regular file', function()
      screen:set_default_attr_ids({
        [1] = { bold = true, foreground = Screen.colors.Blue1 },
        [2] = { bold = true, reverse = true },
        [3] = { bold = true, foreground = Screen.colors.SeaGreen },
        [4] = { reverse = true },
      })

      local cwd = fn.getcwd()
      local msg = cwd
        .. pathsep
        .. 'Xfile is not trusted. To enable it, choose (v)iew then run `:trust`.'
      if #msg >= screen._width then
        pending('path too long')
        return
      end

      -- Need to use feed_command instead of exec_lua because of the confirmation prompt
      feed_command([[lua vim.secure.read('Xfile')]])
      screen:expect([[
        {MATCH: +}|
        {1:~{MATCH: +}}|*3
        {2:{MATCH: +}}|
        :lua vim.secure.read('Xfile'){MATCH: +}|
        {3:]] .. msg .. [[}{MATCH: +}|
        {3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
      ]])
      feed('d')
      screen:expect([[
        ^{MATCH: +}|
        {1:~{MATCH: +}}|*6
        {MATCH: +}|
      ]])

      local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust'))
      eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust))
      eq(vim.NIL, exec_lua([[return vim.secure.read('Xfile')]]))