Skip to content

Commit

Permalink
fix some problems that prevent tests from running
Browse files Browse the repository at this point in the history
  • Loading branch information
kimshrier committed Nov 28, 2024
1 parent 29dfd9c commit bc8938e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
23 changes: 4 additions & 19 deletions common/testing/testing.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,15 @@ import regex
// so that they can be used as more specific errors,
// in place of `return error(message)`
struct DidNotFailError implements IError {
Error
msg string
}

pub fn (err DidNotFailError) msg() string {
return err.msg()
MessageError
}

struct DoesNotWorkError implements IError {
Error
msg string
}

pub fn (err DoesNotWorkError) msg() string {
return err.msg()
MessageError
}

struct ExitCodesDifferError implements IError {
Error
msg string
}

pub fn (err ExitCodesDifferError) msg() string {
return err.msg()
MessageError
}

// CommandPair remembers what original command we are trying to test against
Expand Down Expand Up @@ -64,7 +49,7 @@ pub fn (p CommandPair) same_results(options string) bool {
// expected_failure - given some options, execute both the original
// and the deputy commands with them, and ensure that they both fail
// with the same exit_code
pub fn (p CommandPair) expected_failure(options string) ?os.Result {
pub fn (p CommandPair) expected_failure(options string) !os.Result {
ores := os.execute('${p.original} ${options}')
if ores.exit_code == 0 {
return DidNotFailError{
Expand Down
38 changes: 19 additions & 19 deletions src/numfmt/numfmt_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ fn test_number_grouping() {

fn test_numfmt() {
mut app := App{}
assert numfmt('2K', mut app, Options{}) or {} == '2000'
assert numfmt('-2M', mut app, Options{}) or {} == '-2000000'
assert numfmt('-2.0M', mut app, Options{ grouping: true }) or {} == '-2,000,000'
assert numfmt('20G', mut app, Options{}) or {} == '20000000000'
assert numfmt('20G', mut app, Options{ grouping: true }) or {} == '20,000,000,000'
assert numfmt('2K', mut app, Options{}) or { '' } == '2000'
assert numfmt('-2M', mut app, Options{}) or { '' } == '-2000000'
assert numfmt('-2.0M', mut app, Options{ grouping: true }) or { '' } == '-2,000,000'
assert numfmt('20G', mut app, Options{}) or { '' } == '20000000000'
assert numfmt('20G', mut app, Options{ grouping: true }) or { '' } == '20,000,000,000'
}

fn test_fields() {
Expand All @@ -46,19 +46,19 @@ fn test_fields() {

fn test_to_options() {
mut app := App{}
assert numfmt('200000', mut app, Options{ to: 'si' }) or {} == '200k'
assert numfmt('2000000', mut app, Options{ to: 'si' }) or {} == '2.0m'
assert numfmt('200000', mut app, Options{ to: 'iec' }) or {} == '196K'
assert numfmt('2000000', mut app, Options{ to: 'iec' }) or {} == '2.0M'
assert numfmt('200000', mut app, Options{ to: 'iec-i' }) or {} == '196Ki'
assert numfmt('2000000', mut app, Options{ to: 'iec-i' }) or {} == '2.0Mi'
assert numfmt('2000000', mut app, Options{ to: 'none' }) or {} == '2000000'
assert numfmt('200000', mut app, Options{ to: 'si' }) or { '' } == '200k'
assert numfmt('2000000', mut app, Options{ to: 'si' }) or { '' } == '2.0m'
assert numfmt('200000', mut app, Options{ to: 'iec' }) or { '' } == '196K'
assert numfmt('2000000', mut app, Options{ to: 'iec' }) or { '' } == '2.0M'
assert numfmt('200000', mut app, Options{ to: 'iec-i' }) or { '' } == '196Ki'
assert numfmt('2000000', mut app, Options{ to: 'iec-i' }) or { '' } == '2.0Mi'
assert numfmt('2000000', mut app, Options{ to: 'none' }) or { '' } == '2000000'

assert numfmt('200000.1', mut app, Options{ to: 'si' }) or {} == '201k'
assert numfmt('2000000.2', mut app, Options{ to: 'si' }) or {} == '2.1m'
assert numfmt('200000.3', mut app, Options{ to: 'iec' }) or {} == '196K'
assert numfmt('2000000.4', mut app, Options{ to: 'iec' }) or {} == '2.0M'
assert numfmt('200000.5', mut app, Options{ to: 'iec-i' }) or {} == '196Ki'
assert numfmt('2000000.6', mut app, Options{ to: 'iec-i' }) or {} == '2.0Mi'
assert numfmt('2000000.6', mut app, Options{ to: 'none' }) or {} == '2000001'
assert numfmt('200000.1', mut app, Options{ to: 'si' }) or { '' } == '201k'
assert numfmt('2000000.2', mut app, Options{ to: 'si' }) or { '' } == '2.1m'
assert numfmt('200000.3', mut app, Options{ to: 'iec' }) or { '' } == '196K'
assert numfmt('2000000.4', mut app, Options{ to: 'iec' }) or { '' } == '2.0M'
assert numfmt('200000.5', mut app, Options{ to: 'iec-i' }) or { '' } == '196Ki'
assert numfmt('2000000.6', mut app, Options{ to: 'iec-i' }) or { '' } == '2.0Mi'
assert numfmt('2000000.6', mut app, Options{ to: 'none' }) or { '' } == '2000001'
}

0 comments on commit bc8938e

Please sign in to comment.