Skip to content

Commit

Permalink
Merge branch 'main' into id
Browse files Browse the repository at this point in the history
  • Loading branch information
syrmel committed Nov 28, 2024
2 parents 91664de + 4fc5f61 commit e9792ce
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 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 @@ -61,6 +46,34 @@ pub fn (p CommandPair) same_results(options string) bool {
return same_results('${p.original} ${options}', '${p.deputy} ${options}')
}

// 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 {
ores := os.execute('${p.original} ${options}')
if ores.exit_code == 0 {
return DidNotFailError{
msg: '${p.original} ${options}'
code: 1
}
}
dres := os.execute('${p.deputy} ${options}')
if dres.exit_code == 0 {
return DidNotFailError{
msg: '${p.deputy} ${options}'
code: 2
}
}
if ores.exit_code != dres.exit_code {
return ExitCodesDifferError{
msg: 'original.exit_code: ${ores.exit_code} != deputy.exit_code: dres.exit_code'
code: 1
}
}
assert true
return dres
}

pub fn (p CommandPair) ensure_help_and_version_options_work() ! {
// For now, assume that the original has --version and --help
// and that they already work correctly.
Expand Down

0 comments on commit e9792ce

Please sign in to comment.