
Plan FEATURE S · Add wc.py CLI that prints line, word and character counts of a file, with tests
Steps
- Write test_wc.py (unittest) with failing tests: counts() on empty text, text with and without a trailing newline, multi-word lines, and non-ASCII characters; plus a main() test for a real file and a missing file (returns 1)
- Create wc.py with counts(text) returning (lines, words, chars) using text.count('\n'), len(text.split()) and len(text), read as UTF-8
- Add main(argv) using argparse for one file path argument that prints the counts and the filename, and prints 'wc.py: <error>' to stderr and returns 1 on OSError; guard with sys.exit(main()) under if __name__ == '__main__'
- Run python3 -m unittest test_wc and the CLI checks, then fix any failures
Checks
- PASS Unit tests for the counting function and the CLI exist and pass
python3 -m unittest test_wc (failed before the work) - PASS Running wc.py on a file prints its line, word and character counts followed by the filename
printf 'a b\nc\n' > /tmp/wc_check.txt && python3 wc.py /tmp/wc_check.txt | grep -q '^ *2 *3 *6 /tmp/wc_check.txt$' (failed before the work) - PASS Running wc.py on a missing file exits with status 1 and a 'wc.py: <error>' message on stderr, with no traceback
python3 wc.py /nonexistent/file >/dev/null 2>/tmp/wc_err.txt; [ $? -eq 1 ] && grep -q '^wc\.py: ' /tmp/wc_err.txt && ! grep -q Traceback /tmp/wc_err.txt (failed before the work)
Changed
Closed T-0001 closed; committed 9c48f19 (2 files). Undo: git revert --no-edit 9c48f19 (tokens: 66506 in, 1919 out)
4 worker turns · 68k tokens · 1m31s · replay it: fm code tui --events demo/examples/new-project.jsonl · the case study