Skip to content

Commit

Permalink
First guess at realpath tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Aug 1, 2021
1 parent 20f2607 commit 9aa39ab
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/realpath.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

TOP="$(readlink -f .)"

testcmd '' '.' "$TOP\n" '' ''
testcmd '-z' '-z . | tr "\0" X' "${TOP}X" '' ''

This comment has been minimized.

Copy link
@enh-google

enh-google Aug 16, 2021

Collaborator

this broke CI because the checked-in toybox realpath doesn't have a -z option... (that's not the only problem, just the first one :-) )

This comment has been minimized.

Copy link
@landley

landley Aug 18, 2021

Author Owner

Sorry, I meant to follow up quickly with realpath code implementing that stuff but got sick then got distracted. (I wrote the tests first to have an outline of what success looks like.)

Working on it...

This comment has been minimized.

Copy link
@enh-google

enh-google Aug 19, 2021

Collaborator

no hurry, i doubt i'll get another chance to try an update this week anyway :-(

(this was the only issue found, though, and wrt https://landley.net/notes.html#06-08-2021 --- no, i haven't seen reports of tar test failures [or of hwasan/gwp-asan catching any issues with tar outside of the toybox tests for that matter].)

This comment has been minimized.

Copy link
@enh-google

enh-google via email Aug 27, 2021

Collaborator
touch file
testcmd 'file' 'file' "$TOP/file\n" '' ''
mkdir -p one/two/three
testcmd 'dir' 'one/two/three' "$TOP/one/two/three\n" '' ''
testcmd '--relative-to' '. --relative-to=one/two/three' '../../..\n' '' ''
testcmd '--relative-base' 'one one/two one/two/three --relative-base=one/two' \
"$TOP/one\n.\nthree\n" '' ''
testcmd '--relative-base stomps --relative-to' \
'--relative-to=.. --relative-base=one/two one' "$TOP/one\n" '' ''
testcmd 'missing defaults to -m' 'missing' "$TOP/missing\n" '' ''
testcmd 'missing -e' '-e missing 2>/dev/null || echo ok' 'ok\n' '' ''

# The -s tests use $PWD instead of $TOP because symlinks in path _to_ here
# should not be resolved either. The shell exports $PWD: use it.
ln -s ./one uno
testcmd '-s' '-s uno/two' "$PWD/uno/two\n" '' ''
ln -s one/two dos
testcmd '-s link/..' '-es dos/three' "$PWD/dos/three\n" '' ''
testcmd '-s .. eats symlink' '-s dos/..' "$PWD\n" '' ''
# In toybox this test is consistent with the previous one
toyonly testing '-s .. eats symlink in $PWD' \
'cd dos && realpath -s ..' "$PWD\n" '' ''
# Logically -es means the _symlink_ should exist, but match behavior...
ln -s missing dangling
testcmd '-es dangling symlink' '-es dangling 2>/dev/null || echo ok' \
'ok\n' '' ''
testcmd '-ms' '-ms dangling/../dos/../one/two' "$PWD/one/two\n" '' ''
ln -s ../two/.. one/two/ichi
testcmd '-es' '-es one/two/ichi/two/ichi/two' "$PWD/one/two/ichi/two/ichi/two\n" '' ''

4 comments on commit 9aa39ab

@landley
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'm not blocked on it, just busy juggling other things and it was Friday so I didn't want to block you pulling in your own fixes I'd just merged. (Which seem to have broken my kernel build by the way: it's erroring about signal 0. Hoping to find time to track that down this weekend...)

"Tests running ahead of implementation" is tabsplosion style technical debt. It means I thought I'd finish this thing real quick and instead got nested interrupts 5 levels deep...

@landley
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, toysh has a lot of aspirational tests (and more in a text file I haven't put in the test suite yet, and even more in blog entries I need to go back and collate), but that's still in pending. :)

@enh-google
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'm not blocked on it, just busy juggling other things and it was Friday so I didn't want to block you pulling in your own fixes I'd just merged. (Which seem to have broken my kernel build by the way: it's erroring about signal 0. Hoping to find time to track that down this weekend...)

"Tests running ahead of implementation" is tabsplosion style technical debt. It means I thought I'd finish this thing real quick and instead got nested interrupts 5 levels deep...

i see that the CI is broken too:

PASS: paste -d '私\0̴̗̞̠eq' - - - - - - 
patch: xsignal 0: Invalid argument
FAIL: patch create file
echo -ne '
--- /dev/null
+++ bork
@@ -0,0 +1,3 @@
+one
+two
+three
' | patch >/dev/null && cat bork
--- expected	2021-08-27 13:44:45.685876590 +0000
+++ actual	2021-08-27 13:44:45.685876590 +0000
make: *** [Makefile:76: tests] Error 1
@@ -1,3 +0,0 @@
-one
-two
-three
Error: Process completed with exit code 2.

(i love that we have CI, but i wish i could "subscribe" to failures...)

anyway, yeah, that looks like my fault. one more change needed to support kill -0:

diff --git a/lib/portability.c b/lib/portability.c
index c95a7526..44259a34 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -467,7 +467,8 @@ void xsignal_all_killers(void *handler)
 
   if (!handler) handler = SIG_DFL;
   for (i = 0; signames[i].num != SIGCHLD; i++)
-    if (signames[i].num != SIGKILL) xsignal(signames[i].num, handler);
+    if (signames[i].num && signames[i].num != SIGKILL)
+      xsignal(signames[i].num, handler);
 }
 
 // Convert a string like "9", "KILL", "SIGHUP", or "SIGRTMIN+2" to a number.

(i'll send that as a patch to the mailing list too for convenience.)

@landley
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I hit that here too (alas right after I committed and pushed it I noticed it broke the kernel build in mkroot). Haven't gotten much toybox dev time since then so I hadn't checked in and pushed my local fix. (Same "start at 1" you already did for list_signals.)

Please sign in to comment.