| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | let tmuxTestSessionName = "test" | 
					
						
							|  |  |  | let defaultTmuxPaneId = g:tmuxTestSessionName . ":0.0" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function InitializeTmuxTestSession() | 
					
						
							| 
									
										
										
										
											2020-10-27 15:15:29 -06:00
										 |  |  | 	call system("tmux new -ds " . g:tmuxTestSessionName . " -c $HOME >/dev/null 2>&1") | 
					
						
							| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | " === test formats ================================================== | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function TmuxTest(shellCommand, paneId = g:defaultTmuxPaneId) | 
					
						
							|  |  |  | 	if a:paneId == g:defaultTmuxPaneId | 
					
						
							| 
									
										
										
										
											2020-10-27 15:15:29 -06:00
										 |  |  | 		silent call InitializeTmuxTestSession() | 
					
						
							| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | 	endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 13:10:33 -07:00
										 |  |  | 	call system("tmux send-keys -t " . a:paneId . " 'clear; " . a:shellCommand . "' Enter") | 
					
						
							| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function SplitPaneTest(shellCommand, verticalSplit = 0) | 
					
						
							|  |  |  | 	if a:verticalSplit | 
					
						
							|  |  |  | 		execute "vertical terminal " . a:shellCommand | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		execute "terminal " . a:shellCommand | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function ShellEscapedTest(shellCommand) | 
					
						
							|  |  |  | 	execute "!" . a:shellCommand | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | " === python-django ================================================= | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function DjangoTmuxTest(paneId = g:defaultTmuxPaneId) | 
					
						
							|  |  |  | 	let l:command = "cd " . getcwd() . "; " . GetDjangoTestCommand() | 
					
						
							|  |  |  | 	call TmuxTest(l:command, a:paneId) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function DjangoSplitTest(verticalSplit = 0) | 
					
						
							|  |  |  | 	let l:command = GetDjangoTestCommand() | 
					
						
							|  |  |  | 	call SplitPaneTest(l:command, a:verticalSplit) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function DjangoTest() | 
					
						
							|  |  |  | 	let l:command = GetDjangoTestCommand() | 
					
						
							|  |  |  | 	call ShellEscapedTest(l:command) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetDjangoTestCommand() | 
					
						
							|  |  |  | 	return GetDjangoManagePy() . " test --keepdb" | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetDjangoManagePy() | 
					
						
							| 
									
										
										
										
											2021-02-05 15:49:55 -07:00
										 |  |  | 	return substitute(expand(getcwd()), "/code.*", "/code/manage.py", "") | 
					
						
							| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-09 15:25:32 -06:00
										 |  |  | " =================================================================== | 
					
						
							|  |  |  | " === dotnet core =================================================== | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function DotnetTest(filter = '') | 
					
						
							|  |  |  | 	let l:command = | 
					
						
							|  |  |  | 				\ 'cd ' . GetDotnetProjectLocation() | 
					
						
							|  |  |  | 				\ . ';' . 'dotnet build -clp:ErrorsOnly' | 
					
						
							|  |  |  | 				\ . ';' . 'cd ' . GetDotnetProjectLocation(1) | 
					
						
							|  |  |  | 				\ . ';' . 'dotnet test -clp:ErrorsOnly' | 
					
						
							|  |  |  | 	if a:filter != '' | 
					
						
							|  |  |  | 		let l:command = l:command . ' --filter ' . a:filter | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 	call TmuxTest(l:command) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-28 11:26:34 -06:00
										 |  |  | function DotnetBuild() | 
					
						
							|  |  |  | 	let l:command = | 
					
						
							|  |  |  | 				\ 'cd ' . GetDotnetProjectLocation() | 
					
						
							|  |  |  | 				\ . ';' . 'dotnet build -clp:ErrorsOnly' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	call TmuxTest(l:command) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-09 15:25:32 -06:00
										 |  |  | function GetDotnetProjectLocation(test = 0) | 
					
						
							|  |  |  | 	let l:projectRoot = substitute(expand(getcwd()), '/code.*', '/code', '') | 
					
						
							| 
									
										
										
										
											2021-06-28 11:26:34 -06:00
										 |  |  | 	let l:projectName = substitute(expand(getcwd()), l:projectRoot . '/\([^/]*\).*', '\1', '') | 
					
						
							| 
									
										
										
										
											2021-04-09 15:25:32 -06:00
										 |  |  | 	if a:test | 
					
						
							|  |  |  | 		let l:testPath = system('ls ' . l:projectRoot . '/**/*.csproj | grep Test | head -1') | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2021-06-28 11:26:34 -06:00
										 |  |  | 		if l:projectName != '' | 
					
						
							|  |  |  | 			let l:testPath = l:projectRoot . '/' . l:projectName | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			let l:testPath = system('ls ' . l:projectRoot . '/**/*.csproj | grep -v Test | head -1') | 
					
						
							|  |  |  | 		endif | 
					
						
							| 
									
										
										
										
											2021-04-09 15:25:32 -06:00
										 |  |  | 	endif | 
					
						
							|  |  |  | 	return substitute(l:testPath, '\(.*\)/.*.csproj.*', '\1', '') | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-19 19:28:35 -06:00
										 |  |  | " =================================================================== | 
					
						
							|  |  |  | " === npm =========================================================== | 
					
						
							|  |  |  | " =================================================================== | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function NpmTmuxTest(paneId = g:defaultTmuxPaneId) | 
					
						
							|  |  |  | 	let l:command = "cd " . getcwd() . "; " . GetNpmTestCommand() | 
					
						
							|  |  |  | 	call TmuxTest(l:command, a:paneId) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function NpmSplitTest(verticalSplit = 0) | 
					
						
							|  |  |  | 	let l:command = GetNpmTestCommand() | 
					
						
							|  |  |  | 	call SplitPaneTest(l:command, a:verticalSplit) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function NpmTest() | 
					
						
							|  |  |  | 	let l:command = GetNpmTestCommand() | 
					
						
							|  |  |  | 	call ShellEscapedTest(l:command) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetNpmTestCommand() | 
					
						
							|  |  |  | 	return "npm test" | 
					
						
							|  |  |  | endfunction |