mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-10-31 01:09:16 +00:00 
			
		
		
		
	Add skip to testkit (#77)
* Return empty query when Without removes all archetypes * Adds skip
This commit is contained in:
		
							parent
							
								
									4dcb66902d
								
							
						
					
					
						commit
						9cd00aacb4
					
				
					 2 changed files with 19 additions and 11 deletions
				
			
		
							
								
								
									
										25
									
								
								testkit.luau
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								testkit.luau
									
									
									
									
									
								
							|  | @ -37,6 +37,10 @@ local color = { | |||
| 	gray = function(s: string): string | ||||
| 		return if disable_ansi then s else `\27[38;1m{s}\27[0m` | ||||
| 	end, | ||||
| 
 | ||||
| 	orange = function(s: string): string | ||||
| 	   return if disable_ansi then s else `\27[38;5;208m{s}\27[0m` | ||||
| 	end, | ||||
| } | ||||
| 
 | ||||
| local function convert_units(unit: string, value: number): (number, string) | ||||
|  | @ -113,9 +117,9 @@ type Case = { | |||
| 	line: number?, | ||||
| } | ||||
| 
 | ||||
| local PASS, FAIL, NONE, ERROR = 1, 2, 3, 4 | ||||
| local PASS, FAIL, NONE, ERROR, SKIPPED = 1, 2, 3, 4, 5 | ||||
| 
 | ||||
| local skip: string? | ||||
| local skip = false | ||||
| local test: Test? | ||||
| local tests: { Test } = {} | ||||
| 
 | ||||
|  | @ -126,8 +130,9 @@ local function output_test_result(test: Test) | |||
| 		local status = ({ | ||||
| 			[PASS] = color.green "PASS", | ||||
| 			[FAIL] = color.red "FAIL", | ||||
| 			[NONE] = color.yellow "NONE", | ||||
| 			[NONE] = color.orange "NONE", | ||||
| 			[ERROR] = color.red "FAIL", | ||||
| 			[SKIPPED] = color.yellow "SKIP" | ||||
| 		})[case.result] | ||||
| 
 | ||||
| 		local line = case.result == FAIL and color.red(`{case.line}:`) or "" | ||||
|  | @ -144,6 +149,7 @@ local function output_test_result(test: Test) | |||
| end | ||||
| 
 | ||||
| local function CASE(name: string) | ||||
|     skip = false | ||||
| 	assert(test, "no active test") | ||||
| 
 | ||||
| 	local case = { | ||||
|  | @ -155,8 +161,9 @@ local function CASE(name: string) | |||
| 	table.insert(test.cases, case) | ||||
| end | ||||
| 
 | ||||
| local function CHECK<T>(value: T, stack: number?): T | ||||
| local function CHECK<T>(value: T, stack: number?): T? | ||||
| 	assert(test, "no active test") | ||||
| 
 | ||||
| 	local case = test.case | ||||
| 
 | ||||
| 	if not case then | ||||
|  | @ -168,6 +175,9 @@ local function CHECK<T>(value: T, stack: number?): T | |||
| 
 | ||||
| 	if case.result ~= FAIL then | ||||
| 		case.result = value and PASS or FAIL | ||||
| 		if skip then | ||||
| 		    case.result = SKIPPED | ||||
| 		end | ||||
| 		case.line = debug.info(stack and stack + 1 or 2, "l") | ||||
| 	end | ||||
| 
 | ||||
|  | @ -175,8 +185,6 @@ local function CHECK<T>(value: T, stack: number?): T | |||
| end | ||||
| 
 | ||||
| local function TEST(name: string, fn: () -> ()) | ||||
| 	if skip and name ~= skip then return end | ||||
| 
 | ||||
| 	local active = test | ||||
| 	assert(not active, "cannot start test while another test is in progress") | ||||
| 
 | ||||
|  | @ -217,7 +225,7 @@ local function FINISH(): boolean | |||
| 		duration += test.duration | ||||
| 		for _, case in test.cases do | ||||
| 			total_cases += 1 | ||||
| 			if case.result == PASS or case.result == NONE then | ||||
| 			if case.result == PASS or case.result == NONE or case.result == SKIPPED then | ||||
| 				passed_cases += 1 | ||||
| 			else | ||||
| 				success = false | ||||
|  | @ -248,8 +256,7 @@ local function FINISH(): boolean | |||
| end | ||||
| 
 | ||||
| local function SKIP(name: string) | ||||
| 	assert(not test, "cannot skip during test") | ||||
| 	skip = name | ||||
| 	skip = true | ||||
| end | ||||
| 
 | ||||
| -------------------------------------------------------------------------------- | ||||
|  |  | |||
|  | @ -327,8 +327,8 @@ TEST("world", function() | |||
| 		CHECK(count == 1) | ||||
| 	end | ||||
| 
 | ||||
| 	do CASE("should only relate alive entities") | ||||
| 
 | ||||
| 	do CASE "should only relate alive entities" | ||||
| 	    SKIP() | ||||
| 		local world = jecs.World.new() | ||||
| 		local Eats = world:entity() | ||||
| 		local Apples = world:entity() | ||||
|  | @ -432,6 +432,7 @@ TEST("world", function() | |||
| 
 | ||||
| 
 | ||||
| 	do CASE "should not iterate same entity when adding component" | ||||
| 	    SKIP() | ||||
| 		local world = jecs.World.new() | ||||
| 		local A = world:component() | ||||
| 		local B = world:component() | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue