#! /usr/bin/env tclsh

file delete -force test1
file delete -force where_am_i
file mkdir test1/test2
if {$tcl_platform(platform) eq {windows}} {
    file link -symbolic test1/test2/link_to_test1 test1
} else {
    file link -symbolic test1/test2/link_to_test1 ../../test1
}

cd test1
set fid [open "in_test1" w]
close $fid
puts "Should be in test1"
puts "    pwd reports:  [pwd]"
puts "    glob reports: [glob -nocomplain -types f -- *] [glob -nocomplain -- */]"

cd test2
set fid [open "in_test2" w]
close $fid
puts "Should be in test2"
puts "    pwd reports:  [pwd]"
puts "    glob reports: [glob -nocomplain -types f -- *] [glob -nocomplain -- */]"

cd link_to_test1
puts "Should be in link_to_test1"
puts "    pwd reports:  [pwd]"
puts "    glob reports: [glob -nocomplain -types f -- *] [glob -nocomplain -- */]"

puts "\nNow cd up one level ..."
cd ..
set fid [open "where_am_i" w]
close $fid
puts "Should be in a) parent of test1, or b) test2"
puts "    pwd reports:  [pwd]"
puts "    glob reports: [glob -nocomplain -types f -- *] [glob -nocomplain -- */]"

# Error: We are actually in test2
if {[file exists test1]} {
    puts "We are in the parent of test1 because test1 exists."
}
if {[file exists in_test2]} {
    puts "We are in test2 because in_test2 exists."
}

cd test1
#cd link_to_test1
