Page MenuHomeFreeBSD

wc: Clean up and modernize.
ClosedPublic

Authored by des on Feb 10 2023, 5:49 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:18 AM
Unknown Object (File)
Tue, May 21, 9:17 AM
Subscribers

Details

Summary
  • Drop <err.h>, which is unnecessary since we use libxo.
  • As per POSIX, report an error if output fails.
  • Fix some type mismatches.
  • Use bool instead of int where appropriate.
  • Avoid repeatedly checking for a null filename.
  • Miscellaneous other tidying.
  • Add tests (partly derived from work performed by SHENG-YI HONG <i19780219111@kimo.com>).

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Feb 10 2023, 5:49 PM

Avoid repeatedly checking for a null filename.

Switch mbrtowc() cases around to avoid awkward line wrapping.

Avoid needless repetitions of a hardcoded buffer size.

Remove unintended test file.

Fix multiline_repeated test.

*sigh* I keep finding more stuff to fix

I also have some WIP tests for wc(1) to be added in D35877

Use printf(1) instead of echo.
Add a test case with only blank lines.
Add a test case with only whitespace.

I also have some WIP tests for wc(1) to be added in D35877

It's unfortunate that this wasn't approved back in the day. Does it cover anything that my tests don't?

In D38496#877177, @des wrote:

I also have some WIP tests for wc(1) to be added in D35877

It's unfortunate that this wasn't approved back in the day. Does it cover anything that my tests don't?

It's my fault that haven't completed it yet but I do plan to work on it with the submitter this week. Do you mind if I go ahead to remove the duplicated ones in D35877 and merge it first? Or you want to get this differential in first? I proposed to add tests first because it would be a good practice for code refactoring, but I can wait if you want.

Add descriptions to test cases.

In D38496#877177, @des wrote:

I also have some WIP tests for wc(1) to be added in D35877

It's unfortunate that this wasn't approved back in the day. Does it cover anything that my tests don't?

It's my fault that haven't completed it yet but I do plan to work on it with the submitter this week. Do you mind if I go ahead to remove the duplicated ones in D35877 and merge it first? Or you want to get this differential in first? I proposed to add tests first because it would be a good practice for code refactoring, but I can wait if you want.

How about we add a comment to wc_test.sh crediting the student?

This revision is now accepted and ready to land.Feb 13 2023, 8:50 PM

Add a few more test and fix the whitespace test.

This revision now requires review to proceed.Feb 14 2023, 11:47 AM

Nit: alphabetize envars.

This revision is now accepted and ready to land.Feb 14 2023, 7:18 PM
This revision was automatically updated to reflect the committed changes.