#!/usr/bin/env python3 """Test script to verify wordcount.py matches wc output.""" import subprocess import json # Get wordcount.py output result = subprocess.run( ['python3', 'wordcount.py', 'test_words.txt'], capture_output=True, text=True ) wc_result = json.loads(result.stdout) wordcount_words = wc_result['words'] # Get wc output wc_output = subprocess.run( ['wc', '-w', 'test_words.txt'], capture_output=True, text=True ) wc_words = int(wc_output.stdout.strip().split()[0]) print(f"wordcount.py: {wordcount_words} words") print(f"wc: {wc_words} words") if wordcount_words == wc_words: print("PASS: Outputs match") exit(0) else: print("FAIL: Outputs differ") exit(1)