blob: 2f7a2ec3487398a06b0c371a6be82731384ecf7d [file] [log] [blame]
Elie De Brauwer528e3ba2012-02-12 14:14:58 +01001#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7# Removal of extra /'s
8testing "basename /-only" "basename ///////" "/\n" "" ""
9testing "basename trailing /" "basename a//////" "a\n" "" ""
Rob Landley7aa651a2012-11-13 17:14:08 -060010testing "basename combined" "basename /////a///b///c///d/////" "d\n" "" ""
Elie De Brauwer528e3ba2012-02-12 14:14:58 +010011
12# Standard suffix behavior.
13testing "basename suffix" "basename a/b/c/d.suffix .suffix" "d\n" "" ""
14
15# A suffix cannot be the entire result.
16testing "basename suffix=result" "basename .txt .txt" ".txt\n" "" ""
17
18# Deal with suffix appearing in the filename
Rob Landley3e7c2592012-02-13 21:13:05 -060019testing "basename reappearing suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" ""
20testing "basename reappearing suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" ""
Elie De Brauwer528e3ba2012-02-12 14:14:58 +010021
22# A suffix should be a real suffix, only a the end.
Rob Landley3e7c2592012-02-13 21:13:05 -060023testing "basename invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" ""