mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	 9ce81f7b2b
			
		
	
	9ce81f7b2b
	
	
	
		
			
			In Windows Lua's os.tmpname() returns relative paths starting with \s, prepend them with $TEMP to generate a valid path. In OS X os.tmpname() returns paths in '/tmp' but they should be in '/private/tmp'. We cannot use os_name() for platform detection because some tests use tempname() before nvim is spawned, instead use one of the following: 1. Set SYSTEM_NAME environment variable before calling the tests, it is set from CMAKE_SYSTEM_NAME(i.e. uname -s or 'Windows') 2. Call uname -s 3. Assume windows
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| require('os')
 | |
| local lfs = require('lfs')
 | |
| 
 | |
| local helpers  = require('test.functional.helpers')(after_each)
 | |
| local eval     = helpers.eval
 | |
| local command  = helpers.command
 | |
| local eq, neq  = helpers.eq, helpers.neq
 | |
| local tempfile = helpers.tmpname()
 | |
| 
 | |
| -- tmpname() also creates the file on POSIX systems. Remove it again.
 | |
| -- We just need the name, ignoring any race conditions.
 | |
| if lfs.attributes(tempfile, 'uid') then
 | |
|   os.remove(tempfile)
 | |
| end
 | |
| 
 | |
| local function assert_file_exists(filepath)
 | |
|   -- Use 2-argument lfs.attributes() so no extra table gets created.
 | |
|   -- We don't really care for the uid.
 | |
|   neq(nil, lfs.attributes(filepath, 'uid'))
 | |
| end
 | |
| 
 | |
| local function assert_file_exists_not(filepath)
 | |
|   eq(nil, lfs.attributes(filepath, 'uid'))
 | |
| end
 | |
| 
 | |
| describe(':profile', function()
 | |
|   before_each(helpers.clear)
 | |
| 
 | |
|   after_each(function()
 | |
|     if lfs.attributes(tempfile, 'uid') ~= nil then
 | |
|       os.remove(tempfile)
 | |
|     end
 | |
|   end)
 | |
| 
 | |
|   it('dump', function()
 | |
|     eq(0, eval('v:profiling'))
 | |
|     command('profile start ' .. tempfile)
 | |
|     eq(1, eval('v:profiling'))
 | |
|     assert_file_exists_not(tempfile)
 | |
|     command('profile dump')
 | |
|     assert_file_exists(tempfile)
 | |
|   end)
 | |
| 
 | |
|   it('stop', function()
 | |
|     command('profile start ' .. tempfile)
 | |
|     assert_file_exists_not(tempfile)
 | |
|     command('profile stop')
 | |
|     assert_file_exists(tempfile)
 | |
|     eq(0, eval('v:profiling'))
 | |
|   end)
 | |
| end)
 |