Skip to content

Commit

Permalink
set LC_ALL=C
Browse files Browse the repository at this point in the history
generate the tempdir differently so this working on Macos ( still working on linux )
keep the tempdir when we have a failure
add a regeression test for readlink
  • Loading branch information
ErwanMAS committed Nov 4, 2023
1 parent cfb24ea commit 464ed1a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tests/custom/03_stdlib/62_loadfile
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ Test loading precompiled bytecode

-- Testcase --
{%
import { readlink } from 'fs';

system(`${readlink('/proc/self/exe')} -T, -c -o ./files/test7.uc -e 'Hello world\n'`);
cur_exe=getenv('ucode_bin');
system(`${cur_exe} -T, -c -o ./files/test7.uc -e 'Hello world\n'`);

let fn = loadfile('./files/test7.uc');
fn();
Expand Down
25 changes: 25 additions & 0 deletions tests/custom/03_stdlib/69_readlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The `readlink()` function will follow symbolink link to find the real name of the file
input to compile from the specified file path instead.

-- Testcase --
{%
import { readlink } from 'fs';
system('touch ./files/test_69.txt');
system('ls -1 ./files/test_69.txt');
system('ln -s ./files/test_69.txt ./files/test_symlink.txt');
system('ls -1 ./files/test_symlink.txt');

final_name=readlink('./files/test_symlink.txt');
print(final_name,"\n");
%}
-- End --

-- File test_69.txt --
test 69 in test_69.txt
-- End --

-- Expect stdout --
./files/test_69.txt
./files/test_symlink.txt
./files/test_69.txt
-- End --
27 changes: 14 additions & 13 deletions tests/custom/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ else
readlink=readlink
fi

export LC_ALL=C

testdir=$(dirname "$0")
topdir=$($readlink -f "$testdir/../..")

line='........................................'
ucode_bin=${UCODE_BIN:-"$topdir/ucode"}
ucode_lib=${UCODE_LIB:-"$topdir"}
export ucode_bin=${UCODE_BIN:-"$topdir/ucode"}
export ucode_lib=${UCODE_LIB:-"$topdir"}

extract_sections() {
local file=$1
Expand Down Expand Up @@ -142,22 +144,22 @@ run_test() {

printf "%s %s " "$name" "${line:${#name}}"

mkdir "/tmp/test.$$"

extract_sections "$file" "/tmp/test.$$"
dir_4_test=$($readlink -f $(mktemp -d /tmp/rt.XXXX ))
extract_sections "$file" "${dir_4_test}"
tests=$?

[ -f "/tmp/test.$$/001.in" ] && testcase_first=1
[ -f "${dir_4_test}/001.in" ] && testcase_first=1

for res in "/tmp/test.$$/"[0-9]*; do
for res in "${dir_4_test}/"[0-9]*; do
case "$res" in
*.in)
count=$((count + 1))

if [ $testcase_first = 1 ]; then
# Flush previous test
if [ -n "$ein" ]; then
run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))
run_testcase $count "${dir_4_test}" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))
eout=""
eerr=""
ecode=""
Expand All @@ -167,7 +169,7 @@ run_test() {

ein=$res
else
run_testcase $count "/tmp/test.$$" "$res" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))
run_testcase $count "${dir_4_test}" "$res" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))

eout=""
eerr=""
Expand All @@ -187,15 +189,14 @@ run_test() {

# Flush last test
if [ $testcase_first = 1 ] && [ -n "$eout$eerr$ecode" ]; then
run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))
run_testcase $count "${dir_4_test}" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1))
fi

rm -r "/tmp/test.$$"

if [ $failed = 0 ]; then
printf "OK\n"
rm -r "${dir_4_test}"
else
printf "%s %s FAILED (%d/%d)\n" "$name" "${line:${#name}}" $failed $tests
printf "%s %s FAILED (%d/%d)\ntemp dir was %s\n" "$name" "${line:${#name}}" $failed $tests $dir_4_test
fi

return $failed
Expand Down

0 comments on commit 464ed1a

Please sign in to comment.