Skip to content

Commit

Permalink
Fix fs.dir_stack tests for Darwin/Windows
Browse files Browse the repository at this point in the history
os.Getwd() calls behave differently on different platforms,
specifically it seems these calls don't fail even when residing in a
deleted directory.

This topic needs to be revisited and the behavior needs to be unified
across platforms if possible.
  • Loading branch information
Rafflesiaceae committed May 21, 2022
1 parent 0177e00 commit 40bb560
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions quicktest.nosh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ assert(exists(tmpdir_otto , dir=True))
assert(exists(tmpdir_otto_neurath , dir=True))

cd(tmpdir)
assert(fs.dir_stack, [], xfail=True)
popd(reset=True)
assert(popd() == None)
assert(fs.dir_stack, [])
Expand All @@ -107,15 +108,26 @@ mkdir(missing_dir)
cd(missing_dir)
remove(missing_dir)

if os.isDarwin: # os.Getwd() calls don't fail on MacOS
cd(tmpdir)

# @TODO unify dir_stack handling on cross platforms, there are currently
# distinct platform behaviors that will make writing scripts behaving the same
# relying on dir_stack a bit of nuisance

# os.Getwd() calls don't fail on some platforms
if os.isDarwin:
start_stack = [tmpdir, missing_dir]
elif os.isWindows:
start_stack = [tmpdir, missing_dir, tmpdir]
else:
start_stack = [tmpdir]

# dir_stack only changes when a new path is pushed
cd(tmpdir)
assert(fs.dir_stack, start_stack)
cd(tmpdir)

if os.isDarwin:
start_stack += [tmpdir]
assert(fs.dir_stack, start_stack)
cd(tmpdir)
assert(fs.dir_stack, start_stack)
Expand All @@ -127,8 +139,8 @@ assert(fs.dir_stack, start_stack + [fs.join(tmpdir, "otto")])
assert(popd(), fs.join(tmpdir, "otto"))
assert(fs.dir_stack, start_stack)
assert(popd(), tmpdir)
assert(popd() == None)
assert(fs.dir_stack, [])

assert(len(fs.dir_stack), len(start_stack)-1)
remove_file_assert(tmpdir_otto_neurath, tmpdir_otto)

# TEST fs.exists/fs.touch/fs.remove - basic
Expand Down

0 comments on commit 40bb560

Please sign in to comment.