Skip to content

Commit

Permalink
Fix rake code
Browse files Browse the repository at this point in the history
  • Loading branch information
yeetengangIntel committed Apr 15, 2024
1 parent 566036d commit 45f0f9f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions spec/need_kconfig_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
def check_config_name(name)
# Check if config name format is valid:
# 1. not start with CONFIG_
return !name.to_s.start_with?("CONFIG_")
!name.to_s.start_with?('CONFIG_')
end

def check_config_value(value)
# Check if value format is valid:
# 1. only contain n, m, y or nothing
# 2. only contain i386, x86_64, or nothing
allowed_chars = /^(n|m|y|i386|x86_64|)$/
return value.match?(allowed_chars) || value.empty?
value.match?(allowed_chars) || value.empty?
end

def preprocess_yaml_file(file_path)
yaml_content = ''

File.open(file_path, 'r') do |file|
file.each_line do |line|
# Skip lines containing conditional directives
Expand All @@ -32,7 +32,7 @@ def preprocess_yaml_file(file_path)

def load_yaml_with_conditionals(file_path)
yaml_content = preprocess_yaml_file(file_path)
YAML.safe_load(yaml_content)
YAML.load(yaml_content)
end

describe 'Check need_kconfig from' do
Expand All @@ -42,25 +42,26 @@ def load_yaml_with_conditionals(file_path)
files.each do |file|
begin
yaml_data = load_yaml_with_conditionals(file)
next if yaml_data.nil?
next if yaml_data.nil? || !yaml_data.is_a?(Hash)

kconfig_section = yaml_data['need_kconfig']

next if kconfig_section.nil?

it file do
if kconfig_section.is_a?(String)
case kconfig_section
when String
var_name = kconfig_section
expect(check_config_name(var_name)).to be_truthy
elsif kconfig_section.is_a?(Array)
when Array
kconfig_section.each do |config|
var_name, var_val = config.is_a?(String) ? [config.split(':').map(&:strip)[0], ""] : [config.keys[0], config.values[0]]
var_name, var_val = config.is_a?(String) ? [config.split(':').map(&:strip)[0], ''] : [config.keys[0], config.values[0]]
conditions = check_config_name(var_name) && check_config_value(var_val)
expect(conditions).to be_truthy
end
end
end
rescue Psych::SyntaxError => e
rescue Psych::SyntaxError
# Expecting need_kconfig will be put in yaml file, so files like include/md/raid_level will be skipped
next
end
Expand Down

0 comments on commit 45f0f9f

Please sign in to comment.