import os
import re
def fix_test_module(file_path):
with open(file_path, 'r') as f:
content = f.read()
original = content
empty_test_pattern = re.compile(
r'(\#\[cfg\(test\)\]\s*mod tests\s*\{\s*)(\s*)(\}\s*)',
re.MULTILINE
)
if 'use super::*;' not in content:
content = empty_test_pattern.sub(r'\1\2\n\2 #[test]\n\2 fn _dummy_test() {}\n\2}\n', content)
if content != original:
with open(file_path, 'w') as f:
f.write(content)
return True
return False
def main():
base_dir = "/Users/zool/RustroverProjects/open-lark/crates/openlark-workflow/src"
fixed_count = 0
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith('.rs'):
file_path = os.path.join(root, file)
try:
with open(file_path, 'r') as f:
content = f.read()
if '#[cfg(test)]' in content and 'mod tests {' in content:
test_match = re.search(r'#\[cfg\(test\)\]\s*mod tests\s*\{([^}]*)\}', content, re.DOTALL)
if test_match:
test_content = test_match.group(1).strip()
if not test_content or test_content == '':
new_test = '''#[cfg(test)]
mod tests {
#[test]
fn _dummy_test() {}
}'''
content = re.sub(
r'#\[cfg\(test\)\]\s*mod tests\s*\{[^}]*\}',
new_test,
content
)
with open(file_path, 'w') as f:
f.write(content)
print(f"Fixed: {file_path}")
fixed_count += 1
except Exception as e:
print(f"Error processing {file_path}: {e}")
print(f"\nTotal files fixed: {fixed_count}")
if __name__ == "__main__":
main()