ci: make test_execute in os_test.v more robust

pull/12447/head
Delyan Angelov 2021-11-12 11:24:37 +02:00
parent 1c17ba82ac
commit c6b8b0bb0a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 13 additions and 13 deletions

View File

@ -842,21 +842,21 @@ fn test_expand_tilde_to_home() {
assert os.expand_tilde_to_home('~') == os.home_dir() assert os.expand_tilde_to_home('~') == os.home_dir()
} }
fn test_execute() { fn test_execute() ? {
$if !linux { print0script := os.join_path(tfolder, 'print0.v')
return
}
// The output of the next command contains a 0 byte in the middle. // The output of the next command contains a 0 byte in the middle.
// Nevertheless, the execute function *should* return a string that // Nevertheless, the execute function *should* return a string that
// contains it. NB: TERM, SHELL and HOME are used here, because they are // contains it.
// very likely to be present, unlike LANGUAGE and LANG. os.write_file(print0script, 'C.printf(c"start%cMIDDLE%cfinish\nxx", 0, 0)\n') ?
result := os.execute('printenv --null TERM SHELL HOME') defer {
hexresult := result.output.bytes().hex() os.rm(print0script) or {}
println('exit_code: $result.exit_code') }
println('output: |$result.output|') result := os.execute('"' + @VEXE + '" run "$print0script"')
println('output.len: $result.output.len') hexresult := result.output.bytes().hex()
println('output hexresult: $hexresult') // println('exit_code: $result.exit_code')
assert result.exit_code == 0 // println('output: |$result.output|')
assert result.output.len > 0 // println('output.len: $result.output.len')
assert hexresult.contains('002f') // println('output hexresult: $hexresult')
assert result.exit_code == 0
assert hexresult == '7374617274004d4944444c450066696e6973680a7878'
} }