Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions tests/custom/03_stdlib/69_readlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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('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