#!/bin/bash # # Copyright 2016 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This test exercises Bash utility implementations. source "$[cd $[dirname $(BASH_SOURCE[0])] && pwd]/unittest.bash" \ || do { echo "Could not source unittest.sh" > !2; exit 1; } source "$[cd $[dirname $(BASH_SOURCE[0])] && pwd]/shell_utils.sh" \ || do { echo "shell_utils.sh not found!" > !2; exit 1; } set -eu cd $TEST_TMPDIR proc assert_fails_to { var -r method = $1 var -r arg = $(2:-) if test -n $arg { $method $arg && fail "'$method' should have failed for '$arg'" } else { $method && fail "'$method' should have failed for empty argument" } true # reset the exit status otherwise the test would be considered failed } proc test_resolve_bad_links { var -r dir = $(FUNCNAME[0]) mkdir -p $dir || fail "mkdir -p $dir" # absolute, non-existent path assert_fails_to resolve_links "$[pwd]/$(dir)/non-existent" # relative, non-existent path assert_fails_to resolve_links "$(dir)/non-existent" # symlink with absolute non-existent target ln -s "/non-existent" "$(dir)/bad-absolute.sym" assert_fails_to resolve_links "$[pwd]/$(dir)/bad-absolute.sym" assert_fails_to resolve_links "$(dir)/bad-absolute.sym" # symlink with relative non-existent target ln -s "non-existent" "$(dir)/bad-relative.sym" assert_fails_to resolve_links "$[pwd]/$(dir)/bad-relative.sym" assert_fails_to resolve_links "$(dir)/bad-relative.sym" # circular symlink ln -s "circular.sym" "$(dir)/circular.sym" assert_fails_to resolve_links "$[pwd]/$(dir)/circular.sym" assert_fails_to resolve_links "$(dir)/circular.sym" } proc test_resolve_non_links { var -r dir = $(FUNCNAME[0]) mkdir -p $dir || fail "mkdir -p $dir" echo hello > "$(dir)/hello.txt" # absolute path to directory assert_equals $[pwd] $[resolve_links $[pwd]] # relative path to directory assert_equals $(dir) $[resolve_links $dir] # relative path to file assert_equals "$(dir)/hello.txt" $[resolve_links "$(dir)/hello.txt] # absolute path to file assert_equals \ "$[pwd]/$(dir)/hello.txt" $[resolve_links "$[pwd]/$(dir)/hello.txt] } proc test_resolve_symlinks { var -r dir = $(FUNCNAME[0]) mkdir -p "$(dir)/a/b" || fail "mkdir -p $(dir)/a/b" echo hello > "$(dir)/hello.txt" ln -s "." "$(dir)/self" ln -s "../hello.txt" "$(dir)/a/sym" ln -s "../sym" "$(dir)/a/b/sym" ln -s ".././sym" "$(dir)/a/b/sym-not-normalized" assert_equals "$(dir)/." $[resolve_links "$(dir)/self] assert_equals "$(dir)/a/../hello.txt" $[resolve_links "$(dir)/a/sym] assert_equals "$(dir)/a/b/../../hello.txt" $[resolve_links "$(dir)/a/b/sym] assert_equals \ "$(dir)/a/b/.././../hello.txt" \ $[resolve_links "$(dir)/a/b/sym-not-normalized] cd $dir assert_equals "./." $[resolve_links "self] assert_equals "./." $[resolve_links "./self] assert_equals "a/../hello.txt" $[resolve_links "a/sym] assert_equals "a/b/../../hello.txt" $[resolve_links "a/b/sym] assert_equals \ "a/b/.././../hello.txt" \ $[resolve_links "a/b/sym-not-normalized] cd a assert_equals "../." $[resolve_links "../self] assert_equals "./../hello.txt" $[resolve_links "sym] assert_equals "./../hello.txt" $[resolve_links "./sym] assert_equals "b/../../hello.txt" $[resolve_links "b/sym] assert_equals \ "b/.././../hello.txt" \ $[resolve_links "b/sym-not-normalized] cd b assert_equals "../../." $[resolve_links "../../self] assert_equals "../../hello.txt" $[resolve_links "../sym] assert_equals "./../../hello.txt" $[resolve_links "sym] assert_equals "./../../hello.txt" $[resolve_links "./sym] assert_equals \ "./.././../hello.txt" \ $[resolve_links "sym-not-normalized] } proc test_normalize_path { assert_equals "." $[normalize_path] assert_equals "." $[normalize_path ".] assert_equals "." $[normalize_path "./.] assert_equals ".." $[normalize_path "..] assert_equals ".." $[normalize_path "./..] assert_equals ".." $[normalize_path "../.] assert_equals "../.." $[normalize_path "../././..] assert_equals "blah" $[normalize_path "blah] assert_equals "blah" $[normalize_path "blah/.] assert_equals "blah" $[normalize_path "blah/./hello/..] assert_equals "blah" $[normalize_path "blah/./hello/../] assert_equals \ "blah/hello" $[normalize_path "blah/./hello/../a/b/.././.././hello] assert_equals "." $[normalize_path "blah/./hello/../a/b/.././.././..] assert_equals ".." $[normalize_path "blah/.././..] assert_equals "../.." $[normalize_path "blah/.././../..] assert_equals "/" $[normalize_path "/] assert_equals "/" $[normalize_path "/.] assert_equals "/" $[normalize_path "/./.] assert_equals "/blah" $[normalize_path "/blah] assert_equals "/blah" $[normalize_path "/blah/.] assert_equals "/blah" $[normalize_path "/blah/./hello/..] assert_equals "/blah" $[normalize_path "/blah/./hello/../] assert_equals "/blah" $[normalize_path "/blah/./hello/../a/b/.././../.] } proc test_get_realpath { var -r dir = $(FUNCNAME[0]) mkdir -p "$(dir)/a/b" || fail "mkdir -p $(dir)/a/b" echo hello > "$(dir)/hello.txt" ln -s "." "$(dir)/self" ln -s "../hello.txt" "$(dir)/a/sym" ln -s "../sym" "$(dir)/a/b/sym" ln -s ".././sym" "$(dir)/a/b/sym-not-normalized" assert_equals "$[pwd]/$(dir)" $[get_real_path "$(dir)/self] assert_equals "$[pwd]/$(dir)/hello.txt" $[get_real_path "$(dir)/a/sym] assert_equals "$[pwd]/$(dir)/hello.txt" $[get_real_path "$(dir)/a/b/sym] assert_equals \ "$[pwd]/$(dir)/hello.txt" \ $[get_real_path "$(dir)/a/b/sym-not-normalized] cd $dir var -r abs_dir = $[pwd] assert_equals $(abs_dir) $[get_real_path "self] assert_equals $(abs_dir) $[get_real_path "./self] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "a/sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "a/b/sym] assert_equals \ "$(abs_dir)/hello.txt" $[get_real_path "a/b/sym-not-normalized] cd a assert_equals $(abs_dir) $[get_real_path "../self] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "./sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "b/sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "b/sym-not-normalized] cd b assert_equals $(abs_dir) $[get_real_path "../../self] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "../sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "./sym] assert_equals "$(abs_dir)/hello.txt" $[get_real_path "sym-not-normalized] assert_fails_to get_real_path "non-existent" ln -s self self assert_fails_to get_real_path "self" } proc test_md5_sum { var -r dir = $(FUNCNAME[0]) mkdir $dir || fail "mkdir $dir" echo hello > "$(dir)/a.txt" echo world > "$(dir)/b.txt" assert_fails_to md5_file assert_fails_to md5_file "non-existent" assert_equals "b1946ac92492d2347c6235b4d2611184" $[md5_file "$(dir)/a.txt] assert_equals "591785b794601e212b260e25925636fd" $[md5_file "$(dir)/b.txt] var sums = $[echo -e \ "b1946ac92492d2347c6235b4d2611184\n591785b794601e212b260e25925636fd] assert_equals $sums $[md5_file "$(dir)/a.txt" "$(dir)/b.txt] } run_suite "Tests for Bash utilities" (CommandList children: [ (AndOr children: [ (C {(source)} { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [63 68] ) ) } ) ] ) left_token: spids: [59 70] ) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [55 76] ) (/unittest.bash) ) } ) (BraceGroup children: [ (Sentence child: (SimpleCommand words: [{(echo)} {(DQ ("Could not source unittest.sh"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[92])] ) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [84] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(source)} { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [115 120] ) ) } ) ] ) left_token: spids: [111 122] ) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [107 128] ) (/shell_utils.sh) ) } ) (BraceGroup children: [ (Sentence child: (SimpleCommand words: [{(echo)} {(DQ ("shell_utils.sh not found!"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[144])] ) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [136] ) ] op_id: Op_DPipe ) (C {(set)} {(-eu)}) (C {(cd)} {(DQ ($ VSub_Name "$TEST_TMPDIR"))}) (FuncDef name: assert_fails_to body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:method) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [181] ) ] spids: [177] ) (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:arg) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [193 196] ) ) } spids: [191] ) ] spids: [187] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$arg"))} {(Lit_Other "]")}) terminator: ) ] action: [ (AndOr children: [ (C {(DQ ($ VSub_Name "$method"))} {(DQ ($ VSub_Name "$arg"))}) (C {(fail)} { (DQ ("'") ($ VSub_Name "$method") ("' should have failed for '") ($ VSub_Name "$arg") ("'") ) } ) ] op_id: Op_DAmp ) ] spids: [-1 213] ) ] else_action: [ (AndOr children: [ (C {(DQ ($ VSub_Name "$method"))}) (C {(fail)} { (DQ ("'") ($ VSub_Name "$method") ("' should have failed for empty argument")) } ) ] op_id: Op_DAmp ) ] spids: [237 255] ) (C {(true)}) ] spids: [174] ) spids: [168 173] ) (FuncDef name: test_resolve_bad_links body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [281 286] ) ) } spids: [279] ) ] spids: [275] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$dir"))}) (C {(fail)} {(DQ ("mkdir -p ") ($ VSub_Name "$dir"))}) ] op_id: Op_DPipe ) (C {(assert_fails_to)} {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [319 321] ) (/) (${ VSub_Name dir) (/non-existent) ) } ) (C {(assert_fails_to)} {(resolve_links)} {(DQ (${ VSub_Name dir) (/non-existent))}) (C {(ln)} {(-s)} {(DQ (/non-existent))} {(DQ (${ VSub_Name dir) (/bad-absolute.sym))}) (C {(assert_fails_to)} {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [373 375] ) (/) (${ VSub_Name dir) (/bad-absolute.sym) ) } ) (C {(assert_fails_to)} {(resolve_links)} {(DQ (${ VSub_Name dir) (/bad-absolute.sym))}) (C {(ln)} {(-s)} {(DQ (non-existent))} {(DQ (${ VSub_Name dir) (/bad-relative.sym))}) (C {(assert_fails_to)} {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [422 424] ) (/) (${ VSub_Name dir) (/bad-relative.sym) ) } ) (C {(assert_fails_to)} {(resolve_links)} {(DQ (${ VSub_Name dir) (/bad-relative.sym))}) (C {(ln)} {(-s)} {(DQ (circular.sym))} {(DQ (${ VSub_Name dir) (/circular.sym))}) (C {(assert_fails_to)} {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [471 473] ) (/) (${ VSub_Name dir) (/circular.sym) ) } ) (C {(assert_fails_to)} {(resolve_links)} {(DQ (${ VSub_Name dir) (/circular.sym))}) ] spids: [272] ) spids: [266 271] ) (FuncDef name: test_resolve_non_links body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [511 516] ) ) } spids: [509] ) ] spids: [505] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$dir"))}) (C {(fail)} {(DQ ("mkdir -p ") ($ VSub_Name "$dir"))}) ] op_id: Op_DPipe ) (SimpleCommand words: [{(echo)} {(hello)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name dir) (/hello.txt))} spids: [543] ) ] ) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [561 563] ) ) } { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [571 573] ) ) } ) ] ) left_token: spids: [567 575] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name dir))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ ($ VSub_Name "$dir"))})] ) left_token: spids: [593 599] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (${ VSub_Name dir) (/hello.txt))})] ) left_token: spids: [618 627] ) ) } ) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [641 643] ) (/) (${ VSub_Name dir) (/hello.txt) ) } { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(resolve_links)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [656 658] ) (/) (${ VSub_Name dir) (/hello.txt) ) } ) ] ) left_token: spids: [652 665] ) ) } ) ] spids: [502] ) spids: [496 501] ) (FuncDef name: test_resolve_symlinks body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [686 691] ) ) } spids: [684] ) ] spids: [680] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(DQ (${ VSub_Name dir) (/a/b))}) (C {(fail)} {(DQ ("mkdir -p ") (${ VSub_Name dir) (/a/b))}) ] op_id: Op_DPipe ) (SimpleCommand words: [{(echo)} {(hello)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name dir) (/hello.txt))} spids: [724] ) ] ) (C {(ln)} {(-s)} {(DQ (.))} {(DQ (${ VSub_Name dir) (/self))}) (C {(ln)} {(-s)} {(DQ (../hello.txt))} {(DQ (${ VSub_Name dir) (/a/sym))}) (C {(ln)} {(-s)} {(DQ (../sym))} {(DQ (${ VSub_Name dir) (/a/b/sym))}) (C {(ln)} {(-s)} {(DQ (.././sym))} {(DQ (${ VSub_Name dir) (/a/b/sym-not-normalized))}) (C {(assert_equals)} {(DQ (${ VSub_Name dir) (/.))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (${ VSub_Name dir) (/self))})] ) left_token: spids: [810 819] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name dir) (/a/../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (${ VSub_Name dir) (/a/sym))})] ) left_token: spids: [833 842] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name dir) (/a/b/../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (${ VSub_Name dir) (/a/b/sym))})] ) left_token: spids: [856 865] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name dir) (/a/b/.././../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(resolve_links)} {(DQ (${ VSub_Name dir) (/a/b/sym-not-normalized))}) ] ) left_token: spids: [883 892] ) ) } ) (C {(cd)} {(DQ ($ VSub_Name "$dir"))}) (C {(assert_equals)} {(DQ (./.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (self))})]) left_token: spids: [911 917] ) ) } ) (C {(assert_equals)} {(DQ (./.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (./self))})]) left_token: spids: [928 934] ) ) } ) (C {(assert_equals)} {(DQ (a/../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (a/sym))})]) left_token: spids: [945 951] ) ) } ) (C {(assert_equals)} {(DQ (a/b/../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (a/b/sym))})]) left_token: spids: [962 968] ) ) } ) (C {(assert_equals)} {(DQ (a/b/.././../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (a/b/sym-not-normalized))})] ) left_token: spids: [983 989] ) ) } ) (C {(cd)} {(a)}) (C {(assert_equals)} {(DQ (../.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (../self))})]) left_token: spids: [1006 1012] ) ) } ) (C {(assert_equals)} {(DQ (./../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (sym))})]) left_token: spids: [1023 1029] ) ) } ) (C {(assert_equals)} {(DQ (./../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (./sym))})]) left_token: spids: [1040 1046] ) ) } ) (C {(assert_equals)} {(DQ (b/../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (b/sym))})]) left_token: spids: [1057 1063] ) ) } ) (C {(assert_equals)} {(DQ (b/.././../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (b/sym-not-normalized))})] ) left_token: spids: [1078 1084] ) ) } ) (C {(cd)} {(b)}) (C {(assert_equals)} {(DQ (../../.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (../../self))})]) left_token: spids: [1101 1107] ) ) } ) (C {(assert_equals)} {(DQ (../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (../sym))})]) left_token: spids: [1118 1124] ) ) } ) (C {(assert_equals)} {(DQ (./../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (sym))})]) left_token: spids: [1135 1141] ) ) } ) (C {(assert_equals)} {(DQ (./../../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(resolve_links)} {(DQ (./sym))})]) left_token: spids: [1152 1158] ) ) } ) (C {(assert_equals)} {(DQ (./.././../hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(resolve_links)} {(DQ (sym-not-normalized))})] ) left_token: spids: [1173 1179] ) ) } ) ] spids: [677] ) spids: [671 676] ) (FuncDef name: test_normalize_path body: (BraceGroup children: [ (C {(assert_equals)} {(DQ (.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ )})]) left_token: spids: [1201 1206] ) ) } ) (C {(assert_equals)} {(DQ (.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (.))})]) left_token: spids: [1217 1223] ) ) } ) (C {(assert_equals)} {(DQ (.))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (./.))})]) left_token: spids: [1234 1240] ) ) } ) (C {(assert_equals)} {(DQ (..))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (..))})]) left_token: spids: [1251 1257] ) ) } ) (C {(assert_equals)} {(DQ (..))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (./..))})]) left_token: spids: [1268 1274] ) ) } ) (C {(assert_equals)} {(DQ (..))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (../.))})]) left_token: spids: [1285 1291] ) ) } ) (C {(assert_equals)} {(DQ (../..))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (../././..))})]) left_token: spids: [1302 1308] ) ) } ) (C {(assert_equals)} {(DQ (blah))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (blah))})]) left_token: spids: [1320 1326] ) ) } ) (C {(assert_equals)} {(DQ (blah))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (blah/.))})]) left_token: spids: [1337 1343] ) ) } ) (C {(assert_equals)} {(DQ (blah))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/./hello/..))})] ) left_token: spids: [1354 1360] ) ) } ) (C {(assert_equals)} {(DQ (blah))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/./hello/../))})] ) left_token: spids: [1371 1377] ) ) } ) (C {(assert_equals)} {(DQ (blah/hello))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/./hello/../a/b/.././.././hello))})] ) left_token: spids: [1390 1396] ) ) } ) (C {(assert_equals)} {(DQ (.))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/./hello/../a/b/.././.././..))})] ) left_token: spids: [1407 1413] ) ) } ) (C {(assert_equals)} {(DQ (..))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/.././..))})] ) left_token: spids: [1424 1430] ) ) } ) (C {(assert_equals)} {(DQ (../..))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (blah/.././../..))})] ) left_token: spids: [1441 1447] ) ) } ) (C {(assert_equals)} {(DQ (/))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (/))})]) left_token: spids: [1459 1465] ) ) } ) (C {(assert_equals)} {(DQ (/))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (/.))})]) left_token: spids: [1476 1482] ) ) } ) (C {(assert_equals)} {(DQ (/))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (/./.))})]) left_token: spids: [1493 1499] ) ) } ) (C {(assert_equals)} {(DQ (/blah))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (/blah))})]) left_token: spids: [1510 1516] ) ) } ) (C {(assert_equals)} {(DQ (/blah))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(normalize_path)} {(DQ (/blah/.))})]) left_token: spids: [1527 1533] ) ) } ) (C {(assert_equals)} {(DQ (/blah))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (/blah/./hello/..))})] ) left_token: spids: [1544 1550] ) ) } ) (C {(assert_equals)} {(DQ (/blah))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (/blah/./hello/../))})] ) left_token: spids: [1561 1567] ) ) } ) (C {(assert_equals)} {(DQ (/blah))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(normalize_path)} {(DQ (/blah/./hello/../a/b/.././../.))})] ) left_token: spids: [1578 1584] ) ) } ) ] spids: [1191] ) spids: [1185 1190] ) (FuncDef name: test_get_realpath body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [1605 1610] ) ) } spids: [1603] ) ] spids: [1599] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(DQ (${ VSub_Name dir) (/a/b))}) (C {(fail)} {(DQ ("mkdir -p ") (${ VSub_Name dir) (/a/b))}) ] op_id: Op_DPipe ) (SimpleCommand words: [{(echo)} {(hello)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name dir) (/hello.txt))} spids: [1643] ) ] ) (C {(ln)} {(-s)} {(DQ (.))} {(DQ (${ VSub_Name dir) (/self))}) (C {(ln)} {(-s)} {(DQ (../hello.txt))} {(DQ (${ VSub_Name dir) (/a/sym))}) (C {(ln)} {(-s)} {(DQ (../sym))} {(DQ (${ VSub_Name dir) (/a/b/sym))}) (C {(ln)} {(-s)} {(DQ (.././sym))} {(DQ (${ VSub_Name dir) (/a/b/sym-not-normalized))}) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [1722 1724] ) (/) (${ VSub_Name dir) ) } { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (${ VSub_Name dir) (/self))})] ) left_token: spids: [1732 1741] ) ) } ) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [1748 1750] ) (/) (${ VSub_Name dir) (/hello.txt) ) } { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (${ VSub_Name dir) (/a/sym))})] ) left_token: spids: [1759 1768] ) ) } ) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [1775 1777] ) (/) (${ VSub_Name dir) (/hello.txt) ) } { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (${ VSub_Name dir) (/a/b/sym))})] ) left_token: spids: [1786 1795] ) ) } ) (C {(assert_equals)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [1804 1806] ) (/) (${ VSub_Name dir) (/hello.txt) ) } { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_real_path)} {(DQ (${ VSub_Name dir) (/a/b/sym-not-normalized))}) ] ) left_token: spids: [1817 1826] ) ) } ) (C {(cd)} {(DQ ($ VSub_Name "$dir"))}) (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:abs_dir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [1843 1845] ) } spids: [1842] ) ] spids: [1838] ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (self))})]) left_token: spids: [1857 1863] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (./self))})]) left_token: spids: [1876 1882] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (a/sym))})]) left_token: spids: [1896 1902] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (a/b/sym))})]) left_token: spids: [1916 1922] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (a/b/sym-not-normalized))})] ) left_token: spids: [1938 1944] ) ) } ) (C {(cd)} {(a)}) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (../self))})]) left_token: spids: [1963 1969] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (sym))})]) left_token: spids: [1983 1989] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (./sym))})]) left_token: spids: [2003 2009] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (b/sym))})]) left_token: spids: [2023 2029] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (b/sym-not-normalized))})] ) left_token: spids: [2043 2049] ) ) } ) (C {(cd)} {(b)}) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (../../self))})]) left_token: spids: [2068 2074] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (../sym))})]) left_token: spids: [2088 2094] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (sym))})]) left_token: spids: [2108 2114] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_real_path)} {(DQ (./sym))})]) left_token: spids: [2128 2134] ) ) } ) (C {(assert_equals)} {(DQ (${ VSub_Name abs_dir) (/hello.txt))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_real_path)} {(DQ (sym-not-normalized))})] ) left_token: spids: [2148 2154] ) ) } ) (C {(assert_fails_to)} {(get_real_path)} {(DQ (non-existent))}) (C {(ln)} {(-s)} {(self)} {(self)}) (C {(assert_fails_to)} {(get_real_path)} {(DQ (self))}) ] spids: [1596] ) spids: [1590 1595] ) (FuncDef name: test_md5_sum body: (BraceGroup children: [ (Assignment keyword: Assign_Local flags: ["'-r'"] pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [2203 2208] ) ) } spids: [2201] ) ] spids: [2197] ) (AndOr children: [ (C {(mkdir)} {(DQ ($ VSub_Name "$dir"))}) (C {(fail)} {(DQ ("mkdir ") ($ VSub_Name "$dir"))}) ] op_id: Op_DPipe ) (SimpleCommand words: [{(echo)} {(hello)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name dir) (/a.txt))} spids: [2233] ) ] ) (SimpleCommand words: [{(echo)} {(world)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name dir) (/b.txt))} spids: [2247] ) ] ) (C {(assert_fails_to)} {(md5_file)}) (C {(assert_fails_to)} {(md5_file)} {(DQ (non-existent))}) (C {(assert_equals)} {(DQ (b1946ac92492d2347c6235b4d2611184))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(md5_file)} {(DQ (${ VSub_Name dir) (/a.txt))})] ) left_token: spids: [2280 2289] ) ) } ) (C {(assert_equals)} {(DQ (591785b794601e212b260e25925636fd))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(md5_file)} {(DQ (${ VSub_Name dir) (/b.txt))})] ) left_token: spids: [2300 2309] ) ) } ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:sums) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(echo)} {(-e)} { (DQ (b1946ac92492d2347c6235b4d2611184) (EscapedLiteralPart token: ) (591785b794601e212b260e25925636fd) ) } ) ] ) left_token: spids: [2318 2330] ) ) } spids: [2316] ) ] spids: [2314] ) (C {(assert_equals)} {(DQ ($ VSub_Name "$sums"))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(md5_file)} {(DQ (${ VSub_Name dir) (/a.txt))} {(DQ (${ VSub_Name dir) (/b.txt))} ) ] ) left_token: spids: [2341 2357] ) ) } ) ] spids: [2194] ) spids: [2188 2193] ) (C {(run_suite)} {(DQ ("Tests for Bash utilities"))}) ] )