toml: improve SKIP reporting, fix formatting
							parent
							
								
									ee858568ff
								
							
						
					
					
						commit
						e03d52d322
					
				| 
						 | 
				
			
			@ -35,7 +35,7 @@ const (
 | 
			
		|||
		'valid/table-array-nest.toml',
 | 
			
		||||
		'valid/table-array-nest-no-keys.toml',
 | 
			
		||||
	]
 | 
			
		||||
 | 
			
		||||
	tests_folder           = os.join_path('test-suite', 'tests')
 | 
			
		||||
	jq                     = os.find_abs_path_of_executable('jq') or { '' }
 | 
			
		||||
	compare_work_dir_root  = os.join_path(os.temp_dir(), 'v', 'toml', 'alexcrichton')
 | 
			
		||||
	// From: https://stackoverflow.com/a/38266731/1904615
 | 
			
		||||
| 
						 | 
				
			
			@ -73,21 +73,22 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
		mut valid := 0
 | 
			
		||||
		mut e := 0
 | 
			
		||||
		for i, valid_test_file in valid_test_files {
 | 
			
		||||
			mut relative := valid_test_file.all_after(os.join_path('test-suite', 'tests')).trim_left(os.path_separator)
 | 
			
		||||
			mut relative := valid_test_file.all_after(tests_folder).trim_left(os.path_separator)
 | 
			
		||||
			$if windows {
 | 
			
		||||
				relative = relative.replace('/', '\\')
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if relative !in valid_exceptions {
 | 
			
		||||
			if relative in valid_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			if !hide_oks {
 | 
			
		||||
				println('OK   [${i + 1}/$valid_test_files.len] "$valid_test_file"...')
 | 
			
		||||
			}
 | 
			
		||||
			toml_doc := toml.parse_file(valid_test_file) ?
 | 
			
		||||
			valid++
 | 
			
		||||
			} else {
 | 
			
		||||
				e++
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" EXCEPTION [$e/$valid_exceptions.len]...')
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		println('$valid/$valid_test_files.len TOML files were parsed correctly')
 | 
			
		||||
		if valid_exceptions.len > 0 {
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +110,7 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
			valid = 0
 | 
			
		||||
			e = 0
 | 
			
		||||
			for i, valid_test_file in valid_test_files {
 | 
			
		||||
				mut relative := valid_test_file.all_after(os.join_path('test-suite', 'tests')).trim_left(os.path_separator)
 | 
			
		||||
				mut relative := valid_test_file.all_after(tests_folder).trim_left(os.path_separator)
 | 
			
		||||
				$if windows {
 | 
			
		||||
					relative = relative.replace('/', '\\')
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			@ -118,7 +119,19 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
					continue
 | 
			
		||||
				}
 | 
			
		||||
				// Skip the file if we know it can't be parsed or we know that the value retrieval needs work.
 | 
			
		||||
				if relative !in valid_exceptions && relative !in valid_value_exceptions {
 | 
			
		||||
				if relative in valid_exceptions {
 | 
			
		||||
					e++
 | 
			
		||||
					idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
				if relative in valid_value_exceptions {
 | 
			
		||||
					e++
 | 
			
		||||
					idx := valid_value_exceptions.index(relative) + 1
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID VALUE EXCEPTION [$idx/$valid_value_exceptions.len]...')
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if !hide_oks {
 | 
			
		||||
					println('OK   [${i + 1}/$valid_test_files.len] "$valid_test_file"...')
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			@ -134,8 +147,7 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
					array_type = 2
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
					os.write_file(v_toml_json_path, to_alexcrichton(toml_doc.ast.table,
 | 
			
		||||
						array_type)) ?
 | 
			
		||||
				os.write_file(v_toml_json_path, to_alexcrichton(toml_doc.ast.table, array_type)) ?
 | 
			
		||||
 | 
			
		||||
				alexcrichton_json := os.read_file(valid_test_file.all_before_last('.') + '.json') ?
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -154,10 +166,6 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
				assert alexcrichton_normalized_json == v_normalized_json
 | 
			
		||||
 | 
			
		||||
				valid++
 | 
			
		||||
				} else {
 | 
			
		||||
					e++
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" EXCEPTION [$e/$valid_value_exceptions.len]...')
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			println('$valid/$valid_test_files.len TOML files were parsed correctly and value checked')
 | 
			
		||||
			if valid_value_exceptions.len > 0 {
 | 
			
		||||
| 
						 | 
				
			
			@ -171,11 +179,17 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
		mut invalid := 0
 | 
			
		||||
		e = 0
 | 
			
		||||
		for i, invalid_test_file in invalid_test_files {
 | 
			
		||||
			mut relative := invalid_test_file.all_after(os.join_path('test-suite', 'tests')).trim_left(os.path_separator)
 | 
			
		||||
			mut relative := invalid_test_file.all_after(tests_folder).trim_left(os.path_separator)
 | 
			
		||||
			$if windows {
 | 
			
		||||
				relative = relative.replace('/', '\\')
 | 
			
		||||
			}
 | 
			
		||||
			if relative !in invalid_exceptions {
 | 
			
		||||
			if relative in invalid_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := invalid_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$invalid_test_files.len] "$invalid_test_file" INVALID EXCEPTION [$idx/$invalid_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if !hide_oks {
 | 
			
		||||
				println('OK   [${i + 1}/$invalid_test_files.len] "$invalid_test_file"...')
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -190,10 +204,6 @@ fn test_alexcrichton_toml_rs() ? {
 | 
			
		|||
				assert true
 | 
			
		||||
			}
 | 
			
		||||
			invalid++
 | 
			
		||||
			} else {
 | 
			
		||||
				e++
 | 
			
		||||
				println('SKIP [${i + 1}/$invalid_test_files.len] "$invalid_test_file" EXCEPTION [$e/$invalid_exceptions.len]...')
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		println('$invalid/$invalid_test_files.len TOML files were parsed correctly')
 | 
			
		||||
		if invalid_exceptions.len > 0 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,27 +57,33 @@ fn test_burnt_sushi_tomltest() ? {
 | 
			
		|||
	this_file := @FILE
 | 
			
		||||
	test_root := os.join_path(os.dir(this_file), 'testdata', 'burntsushi', 'toml-test',
 | 
			
		||||
		'tests')
 | 
			
		||||
	if os.is_dir(test_root) {
 | 
			
		||||
	if !os.is_dir(test_root) {
 | 
			
		||||
		println('No test data directory found in "$test_root"')
 | 
			
		||||
		assert true
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	valid_folder := os.join_path('toml-test', 'tests', 'valid')
 | 
			
		||||
	invalid_folder := os.join_path('toml-test', 'tests', 'invalid')
 | 
			
		||||
	valid_test_files := os.walk_ext(os.join_path(test_root, 'valid'), '.toml')
 | 
			
		||||
	println('Testing $valid_test_files.len valid TOML files...')
 | 
			
		||||
	mut valid := 0
 | 
			
		||||
	mut e := 0
 | 
			
		||||
	for i, valid_test_file in valid_test_files {
 | 
			
		||||
			mut relative := valid_test_file.all_after(os.join_path('toml-test', 'tests',
 | 
			
		||||
				'valid')).trim_left(os.path_separator)
 | 
			
		||||
		mut relative := valid_test_file.all_after(valid_folder).trim_left(os.path_separator)
 | 
			
		||||
		$if windows {
 | 
			
		||||
			relative = relative.replace('/', '\\')
 | 
			
		||||
		}
 | 
			
		||||
			if relative !in valid_exceptions {
 | 
			
		||||
		if relative in valid_exceptions {
 | 
			
		||||
			e++
 | 
			
		||||
			idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
			println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if !hide_oks {
 | 
			
		||||
			println('OK   [${i + 1}/$valid_test_files.len] "$valid_test_file"...')
 | 
			
		||||
		}
 | 
			
		||||
		toml_doc := toml.parse_file(valid_test_file) ?
 | 
			
		||||
		valid++
 | 
			
		||||
			} else {
 | 
			
		||||
				e++
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" EXCEPTION [$e/$valid_exceptions.len]...')
 | 
			
		||||
			}
 | 
			
		||||
	}
 | 
			
		||||
	println('$valid/$valid_test_files.len TOML files were parsed correctly')
 | 
			
		||||
	if valid_exceptions.len > 0 {
 | 
			
		||||
| 
						 | 
				
			
			@ -99,13 +105,24 @@ fn test_burnt_sushi_tomltest() ? {
 | 
			
		|||
		valid = 0
 | 
			
		||||
		e = 0
 | 
			
		||||
		for i, valid_test_file in valid_test_files {
 | 
			
		||||
				mut relative := valid_test_file.all_after(os.join_path('toml-test', 'tests',
 | 
			
		||||
					'valid')).trim_left(os.path_separator)
 | 
			
		||||
			mut relative := valid_test_file.all_after(valid_folder).trim_left(os.path_separator)
 | 
			
		||||
			$if windows {
 | 
			
		||||
				relative = relative.replace('/', '\\')
 | 
			
		||||
			}
 | 
			
		||||
			// Skip the file if we know it can't be parsed or we know that the value retrieval needs work.
 | 
			
		||||
				if relative !in valid_exceptions && relative !in valid_value_exceptions {
 | 
			
		||||
			if relative in valid_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			if relative in valid_value_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := valid_value_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID VALUE EXCEPTION [$idx/$valid_value_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if !hide_oks {
 | 
			
		||||
				println('OK   [${i + 1}/$valid_test_files.len] "$valid_test_file"...')
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -134,28 +151,28 @@ fn test_burnt_sushi_tomltest() ? {
 | 
			
		|||
			assert bs_normalized_json == v_normalized_json
 | 
			
		||||
 | 
			
		||||
			valid++
 | 
			
		||||
				} else {
 | 
			
		||||
					e++
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" EXCEPTION [$e/$valid_value_exceptions.len]...')
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	println('$valid/$valid_test_files.len TOML files were parsed correctly and value checked')
 | 
			
		||||
	if valid_value_exceptions.len > 0 {
 | 
			
		||||
		println('TODO Skipped value checks of $valid_value_exceptions.len valid TOML files...')
 | 
			
		||||
	}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	invalid_test_files := os.walk_ext(os.join_path(test_root, 'invalid'), '.toml')
 | 
			
		||||
	println('Testing $invalid_test_files.len invalid TOML files...')
 | 
			
		||||
	mut invalid := 0
 | 
			
		||||
	e = 0
 | 
			
		||||
	for i, invalid_test_file in invalid_test_files {
 | 
			
		||||
			mut relative := invalid_test_file.all_after(os.join_path('toml-test', 'tests',
 | 
			
		||||
				'invalid')).trim_left(os.path_separator)
 | 
			
		||||
		mut relative := invalid_test_file.all_after(invalid_folder).trim_left(os.path_separator)
 | 
			
		||||
		$if windows {
 | 
			
		||||
			relative = relative.replace('/', '\\')
 | 
			
		||||
		}
 | 
			
		||||
			if relative !in invalid_exceptions {
 | 
			
		||||
		if relative in invalid_exceptions {
 | 
			
		||||
			e++
 | 
			
		||||
			idx := invalid_exceptions.index(relative) + 1
 | 
			
		||||
			println('SKIP [${i + 1}/$invalid_test_files.len] "$invalid_test_file" INVALID EXCEPTION [$idx/$invalid_exceptions.len]...')
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if !hide_oks {
 | 
			
		||||
			println('OK   [${i + 1}/$invalid_test_files.len] "$invalid_test_file"...')
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -170,19 +187,11 @@ fn test_burnt_sushi_tomltest() ? {
 | 
			
		|||
			assert true
 | 
			
		||||
		}
 | 
			
		||||
		invalid++
 | 
			
		||||
			} else {
 | 
			
		||||
				e++
 | 
			
		||||
				println('SKIP [${i + 1}/$invalid_test_files.len] "$invalid_test_file" EXCEPTION [$e/$invalid_exceptions.len]...')
 | 
			
		||||
			}
 | 
			
		||||
	}
 | 
			
		||||
	println('$invalid/$invalid_test_files.len TOML files were parsed correctly')
 | 
			
		||||
	if invalid_exceptions.len > 0 {
 | 
			
		||||
		println('TODO Skipped parsing of $invalid_exceptions.len invalid TOML files...')
 | 
			
		||||
	}
 | 
			
		||||
	} else {
 | 
			
		||||
		println('No test data directory found in "$test_root"')
 | 
			
		||||
		assert true
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// to_burntsushi returns a BurntSushi compatible json string converted from the `value` ast.Value.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,7 +91,7 @@ fn test_iarna_toml_spec_tests() ? {
 | 
			
		|||
 | 
			
		||||
			if relative in valid_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := valid_exceptions.index(relative)
 | 
			
		||||
				idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -130,17 +130,15 @@ fn test_iarna_toml_spec_tests() ? {
 | 
			
		|||
				// Skip the file if we know it can't be parsed or we know that the value retrieval needs work.
 | 
			
		||||
				if relative in valid_exceptions {
 | 
			
		||||
					e++
 | 
			
		||||
					idx := valid_exceptions.index(relative)
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [${
 | 
			
		||||
						idx + 1}/$valid_exceptions.len]...')
 | 
			
		||||
					idx := valid_exceptions.index(relative) + 1
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID EXCEPTION [$idx/$valid_exceptions.len]...')
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if relative in valid_value_exceptions {
 | 
			
		||||
					e++
 | 
			
		||||
					idx := valid_value_exceptions.index(relative)
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID VALUE EXCEPTION [${
 | 
			
		||||
						idx + 1}/$valid_value_exceptions.len]...')
 | 
			
		||||
					idx := valid_value_exceptions.index(relative) + 1
 | 
			
		||||
					println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" VALID VALUE EXCEPTION [$idx/$valid_value_exceptions.len]...')
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -162,7 +160,7 @@ fn test_iarna_toml_spec_tests() ? {
 | 
			
		|||
					}
 | 
			
		||||
					if !do_yaml_conversion || relative in yaml_value_exceptions {
 | 
			
		||||
						e++
 | 
			
		||||
						idx := yaml_value_exceptions.index(relative)
 | 
			
		||||
						idx := yaml_value_exceptions.index(relative) + 1
 | 
			
		||||
						println('SKIP [${i + 1}/$valid_test_files.len] "$valid_test_file" YAML VALUE EXCEPTION [$idx/$valid_value_exceptions.len]...')
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -239,7 +237,7 @@ fn test_iarna_toml_spec_tests() ? {
 | 
			
		|||
			}
 | 
			
		||||
			if relative in invalid_exceptions {
 | 
			
		||||
				e++
 | 
			
		||||
				idx := invalid_exceptions.index(relative)
 | 
			
		||||
				idx := invalid_exceptions.index(relative) + 1
 | 
			
		||||
				println('SKIP [${i + 1}/$invalid_test_files.len] "$invalid_test_file" INVALID EXCEPTION [$idx/$invalid_exceptions.len]...')
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue