robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f9ea56f959
master
1const std =@import ( "std" ); 2const LazyPath =std . Build . LazyPath ; 3 4pub fn testStep ( b : * std . Build , kind : [] const u8 , nvim_bin : * std . Build . Step . Compile , config_dir : LazyPath , include_path : ? [] const LazyPath ) ! * std . Build . Step . Run { 5const test_step =b . addRunArtifact ( nvim_bin ); 6test_step . addArg ( "-l" ); 7test_step . addFileArg ( b . path ( "./test/runner.lua" )); 8if ( include_path ) | paths | { 9for ( paths ) |path |{ 10test_step . addPrefixedDirectoryArg ( "-I" , path ); 11} 12} 13test_step . addArg ( b . fmt ( "-P { s } " , .{ b . install_path })); 14// TODO(bfredl): investigate parallel test groups like in cmake 15test_step . addArg ( b . fmt ( "-X { s } /Xdg_dir" , .{ b . install_path })); 16test_step . addArg ( "-v" ); 17test_step . addArg ( b . fmt ( "--helper=./test/ { s } /preload.lua" , .{ kind })); 18test_step . addPrefixedFileArg ( "--lpath=" , config_dir . path ( b , "?.lua" )); // FULING: not a real file but works anyway? 19test_step . addArg ( b . fmt ( "--default-path=./test/ { s } " , .{ kind })); 20if ( b . args ) | args | test_step . addArgs ( args ); 21 22const env =test_step . getEnvMap (); 23try env . put ( "NVIM_TEST" , "1" ); 24if ( env . get ( "NVIM_LOG_FILE" ) == null ) { 25try env . put ( "NVIM_LOG_FILE" , b . fmt ( " { s } /nvim.log" , .{ b . install_path })); 26} 27 28_ = env . swapRemove ( "NVIM" ); 29_ = env . swapRemove ( "XDG_DATA_DIRS" ); 30return test_step ; 31} 32 33pub fn test_steps ( b : * std . Build , nvim_bin : * std . Build . Step . Compile , depend_on : * std . Build . Step , config_dir : LazyPath , unit_paths : ? [] const LazyPath ) ! void { 34const empty_dir =b . addWriteFiles (); 35_ = empty_dir . add ( ".touch" , "" ); 36const tmpdir_create =b . addInstallDirectory (.{ . source_dir =empty_dir . getDirectory (), . install_dir =. prefix , . install_subdir ="Xtest_tmpdir/" }); 37 38const functional_tests =try testStep ( b , "functional" , nvim_bin , config_dir , null ); 39functional_tests . step . dependOn ( depend_on ); 40functional_tests . step . dependOn ( & tmpdir_create . step ); 41 42const functionaltest_step =b . step ( "functionaltest" , "run functional tests" ); 43functionaltest_step . dependOn ( & functional_tests . step ); 44 45const old_tests =b . addRunArtifact ( nvim_bin ); 46old_tests . addArg ( "-l" ); 47old_tests . addFileArg ( b . path ( "./test/old/runner.lua" )); 48if ( b . args ) | args | { 49old_tests . addArgs ( args ); // accept TEST_FILE as a positional argument 50} 51const env =old_tests . getEnvMap (); 52try env . put ( "BUILD_DIR" , b . install_path ); 53 54const oldtest_step =b . step ( "oldtest" , "run old tests" ); 55oldtest_step . dependOn ( & old_tests . step ); 56oldtest_step . dependOn ( depend_on ); 57 58if ( unit_paths ) | paths | { 59const unit_tests =try testStep ( b , "unit" , nvim_bin , config_dir , paths ); 60unit_tests . step . dependOn ( depend_on ); 61unit_tests . step . dependOn ( & tmpdir_create . step ); 62 63const unittest_step =b . step ( "unittest" , "run unit tests" ); 64unittest_step . dependOn ( & unit_tests . step ); 65} 66}