Skip to content

Commit

Permalink
use os.chdir(testing.temp_folder)! consistently in all `fn testsuit…
Browse files Browse the repository at this point in the history
…e_begin() {}`
  • Loading branch information
spytheman committed Jan 29, 2024
1 parent b1ab945 commit 74d13f3
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/arch/arch_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import common.testing
import os

const util = 'arch'

Expand All @@ -12,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
4 changes: 4 additions & 0 deletions src/base64/base64_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
1 change: 1 addition & 0 deletions src/cksum/cksum_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn test_help_and_version() {
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
os.write_file(test1_txt_path, 'Hello World!\nHow are you?')!
os.write_file(test2_txt_path, 'a'.repeat(128 * 1024 + 5))!
}
Expand Down
4 changes: 4 additions & 0 deletions src/dirname/dirname_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
1 change: 1 addition & 0 deletions src/expand/expand_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cmd = testing.new_paired_command(platform_util, executable_under_test)
const test_txt_path = os.join_path(testing.temp_folder, 'test.txt')

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
mut f := os.open_file(test_txt_path, 'wb')!
for l in testtxtcontent {
f.writeln('${l}')!
Expand Down
4 changes: 4 additions & 0 deletions src/expr/expr_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ const tests = [
r"'(' 2 a",
]

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_results() {
mut failed := []string{}
for test in tests {
Expand Down
4 changes: 4 additions & 0 deletions src/factor/factor_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
1 change: 1 addition & 0 deletions src/fold/fold_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn test_help_and_version() {
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
mut f := os.open_file(test_txt_path, 'wb')!
for l in testtxtcontent {
f.writeln('${l}') or {}
Expand Down
1 change: 1 addition & 0 deletions src/head/head_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cmd = testing.new_paired_command(platform_util, executable_under_test)
const test_txt_path = os.join_path(testing.temp_folder, 'test.txt')

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
mut f := os.open_file(test_txt_path, 'wb')!
for l in testtxtcontent {
f.writeln('${l}')!
Expand Down
1 change: 1 addition & 0 deletions src/mkdir/mkdir_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const eol = testing.output_eol()
const tfolder = os.join_path(os.temp_dir(), 'coreutils', 'mkdir_test')

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
eprintln('testsuite_begin, tfolder = ${tfolder}')
os.rmdir_all(tfolder) or {}
assert !os.is_dir(tfolder)
Expand Down
5 changes: 5 additions & 0 deletions src/printenv/printenv_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import common.testing
import os

const util = 'printenv'

Expand All @@ -12,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
4 changes: 4 additions & 0 deletions src/shuf/shuf_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const shuf = testing.prepare_executable('shuf')

const test_txt_path = os.join_path(testing.temp_folder, 'test.txt')

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_echo() {
res := os.execute('${shuf} -e aa bb')
assert res.output == 'aa${eol}bb${eol}' || res.output == 'bb${eol}aa${eol}'
Expand Down
4 changes: 4 additions & 0 deletions src/sleep/sleep_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const cmd = testing.new_paired_command(platform_util, executable_under_test)

const cmd_ns = 'sleep'

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
5 changes: 5 additions & 0 deletions src/uname/uname_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import common.testing
import os

const util = 'uname'

Expand All @@ -12,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down
1 change: 1 addition & 0 deletions src/uniq/uniq_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn test_posix_spec_case_4_zero_term() {
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
os.write_file(posix_test_path_newline, posix_test_data.join('\n'))!
os.write_file(posix_test_path_zeroterm, posix_test_data.join('\0'))!
os.mkdir('foo')!
Expand Down
4 changes: 4 additions & 0 deletions src/unlink/unlink_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ fn call_for_test(args string) os.Result {
return res
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

// TODO: The following tests fail in a Windows environment; need to
// investigate what gives.
fn test_target_does_not_exist() {
Expand Down
5 changes: 5 additions & 0 deletions src/uptime/uptime_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import common.testing
import os

const util = 'uptime'

Expand All @@ -14,6 +15,10 @@ const executable_under_test = if supported_platform {
''
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

const cmd = testing.new_paired_command(util, executable_under_test)

fn test_help_and_version() {
Expand Down
1 change: 1 addition & 0 deletions src/wc/wc_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn test_help_and_version() {
}

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
os.write_file(test1_txt_path, 'Hello World!\nHow are you?')!
os.write_file(test2_txt_path, 'twolinesonebreak\nbreakline')!
os.write_file(test3_txt_path, 'twolinestwobreaks\nbreakline\n')!
Expand Down
5 changes: 5 additions & 0 deletions src/whoami/whoami_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import common.testing
import os

const util = 'whoami'

Expand All @@ -12,6 +13,10 @@ const executable_under_test = testing.prepare_executable(util)

const cmd = testing.new_paired_command(platform_util, executable_under_test)

fn testsuite_begin() {
os.chdir(testing.temp_folder)!
}

fn test_help_and_version() {
cmd.ensure_help_and_version_options_work()!
}
Expand Down

0 comments on commit 74d13f3

Please sign in to comment.