Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ compare against the true GNU coreutils version on the Linux-based tests first.
| ✓ | nohup | Run a command immune to hangups | ✓ |
| ✓ | nproc | Print the number of available processors | ✓ |
| ✓ | numfmt | Reformat numbers | ✓ |
| | od | Write files in octal or other formats | ✓ |
| ✓ | od | Write files in octal or other formats | ✓ |
| ✓ | paste | Merge lines of files | ✓ |
| | pathchk | Check file name validity and portability | ✓ |
| | pinky | Lightweight finger | |
Expand Down
13 changes: 7 additions & 6 deletions build.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ for dir in dirs_to_compile {
// Released
_ := <-ch
}
mut final_args := '-Wimpure-v'
for arg in vargs {
final_args += ' ' + arg
}
cmd := @VEXE + ' ${final_args} -o "${curdir}/bin/${dir}" "./${dir}"'
// `os.exec` takes an argument array rather than a command string, so the
// word splitting happens here instead of in a shell. Each argument is passed
// as it is, which is why a path with a space in it needs no quoting.
mut cmd := [@VEXE, '-Wimpure-v']
cmd << vargs
cmd << ['-o', '${curdir}/bin/${dir}', './${dir}']
sw := time.new_stopwatch()
execute_or_panic(cmd)
os.exec_or_panic(cmd)
print_ch <- 'compiling ${dir:-20s}... took ${sw.elapsed().milliseconds()}ms .\n'
}()
}
Expand Down
34 changes: 33 additions & 1 deletion src/cksum/cksum_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import os

const rig = testing.prepare_rig(util: 'cksum')
const executable_under_test = rig.executable_under_test
const eol = testing.output_eol()
// GNU writes a bare LF to stdout and stderr on every platform, Windows included,
// so this is not common's eol. Measured here, each of these utilities ends its
// output with byte 10 and not with 13,10:
//
// cksum, wc, sum, mkdir -v, head
//
// With common's eol the expectations were disagreeing by one byte per line on
// Windows, which is what test . has been reporting as a content difference.
const eol = '\n'
const test1_txt_path = os.join_path(rig.temp_dir, 'test1.txt')
const test2_txt_path = os.join_path(rig.temp_dir, 'test2.txt')
const test3_txt_path = os.join_path(rig.temp_dir, 'test3.txt')
Expand Down Expand Up @@ -31,7 +39,31 @@ fn test_help_and_version() {
rig.assert_help_and_version_options_work()
}

// Standard input cannot be fed from a test on Windows.
//
// The test used to say `cat path | cksum`, which is a command line and not a pipe
// there: there is no cat, so the shell answered with exit 255 and the test was
// reporting a failure in a utility it never reached. Going through `cmd /c type`
// instead does not work either, because os.exec quotes each argument and cmd then
// sees a quoted pipe as part of a filename:
//
// The filename, directory name, or volume label syntax is incorrect.
//
// So the tests that need standard input say so and return, rather than failing for
// a reason that has nothing to do with cksum. The ones that pass a file work here
// and are not skipped.
fn no_standard_input_here() bool {
$if windows {
println('feeding standard input from a test needs a pipe this platform has not got, skipping')
return true
}
return false
}

fn test_stdin() {
if no_standard_input_here() {
return
}
res := os.execute('cat ${test1_txt_path} | ${executable_under_test}')

assert res.exit_code == 0
Expand Down
1 change: 0 additions & 1 deletion src/expand/expand_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import common.testing

const rig = testing.prepare_rig(util: 'expand')
const executable_under_test = rig.executable_under_test
const eol = testing.output_eol()
const test_txt_path = os.join_path(rig.temp_dir, 'test.txt')

fn testsuite_begin() {
Expand Down
10 changes: 9 additions & 1 deletion src/head/head_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import os
const rig = testing.prepare_rig(util: 'head')
const cmd = rig.cmd
const executable_under_test = rig.executable_under_test
const eol = testing.output_eol()
// GNU writes a bare LF to stdout and stderr on every platform, Windows included,
// so this is not common's eol. Measured here, each of these utilities ends its
// output with byte 10 and not with 13,10:
//
// cksum, wc, sum, mkdir -v, head
//
// With common's eol the expectations were disagreeing by one byte per line on
// Windows, which is what test . has been reporting as a content difference.
const eol = '\n'
const test_txt_path = os.join_path(rig.temp_dir, 'test.txt')

fn testsuite_begin() {
Expand Down
10 changes: 9 additions & 1 deletion src/mkdir/mkdir_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import os
import common.testing

const rig = testing.prepare_rig(util: 'mkdir')
const eol = testing.output_eol()
// GNU writes a bare LF to stdout and stderr on every platform, Windows included,
// so this is not common's eol. Measured here, each of these utilities ends its
// output with byte 10 and not with 13,10:
//
// cksum, wc, sum, mkdir -v, head
//
// With common's eol the expectations were disagreeing by one byte per line on
// Windows, which is what test . has been reporting as a content difference.
const eol = '\n'

// A lot of the following has been lifted directly from os_test.v in vlib,
// since it is a good demonstration of the ideal/canonical method of testing
Expand Down
16 changes: 0 additions & 16 deletions src/numfmt/numfmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,6 @@ fn readable_size(size f64, unit Unit, rounding string) !string {
return number_str(size)
}

// number_str renders n the way GNU numfmt does: plain decimal digits, never
// exponent notation, and no trailing ".0" on an integral value. f64.str()
// switches to scientific notation above a million and always keeps the
// fractional part, which would turn 2000000 into "2e+06" and 2000 into "2000.0".
fn number_str(n f64) string {
s := n.strlong()
if s.ends_with('.0') {
return s[..s.len - 2]
}
return s
}

fn commaize(num f64) string {
str := strconv.f64_to_str_l(num)
n, _ := str.split_once('.') or { return 'oops' }
Expand Down Expand Up @@ -270,10 +258,6 @@ fn handle_error(msg string, mut app App, options Options) string {
return ''
}

fn print_space() {
print_character(` `)
}

@[noreturn]
fn exit_message(msg string, exit_code int) {
eprintln(msg)
Expand Down
10 changes: 6 additions & 4 deletions src/numfmt/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ fn get_options() Options {
'right-align; negative N will left-align; padding is\n${flag.space}' +
'ignored if the output is wider than N; the default is to\n${flag.space}' +
'automatically pad if a whitespace is found')
round := fp.string('round', 0, 'from-zero',
// Named `round_method`, because a local `round` shadows the `round` function
// and `-W` turns that notice into an error.
round_method := fp.string('round', 0, 'from-zero',
'use METHOD for rounding when scaling; METHOD can be:\n${flag.space}' +
'up, down, from-zero (default), towards-zero, nearest')
suffix := fp.string('suffix', 0, '',
Expand Down Expand Up @@ -122,8 +124,8 @@ fn get_options() Options {
exit_error('unrecognized scale option ${to}')
}

if round !in rounds {
exit_error('unrecognized rounding option ${round}')
if round_method !in rounds {
exit_error('unrecognized rounding option ${round_method}')
}

return Options{
Expand All @@ -136,7 +138,7 @@ fn get_options() Options {
numbers: numbers
padding: padding
pformat: pformat
round: round
round: round_method
suffix: suffix
to: to
to_unit: to_unit
Expand Down
Loading