Skip to content

Commit

Permalink
add ipfs help sub-command test
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kejie Zhang <[email protected]>
  • Loading branch information
kjzz committed Oct 30, 2018
1 parent 08c75aa commit 53fe9c9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
8 changes: 6 additions & 2 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ func mainRet() int {
if os.Args[1] == "help" {
if len(os.Args) > 2 {
os.Args = append(os.Args[:1], os.Args[2:]...)
os.Args = append(os.Args, "-h")
// Handle `ipfs help --help`
// append `--help`,when the command is not `ipfs help --help`
if os.Args[1] != "--help" {
os.Args = append(os.Args, "--help")
}
} else {
os.Args[1] = "-h"
os.Args[1] = "--help"
}
}
}
Expand Down
35 changes: 15 additions & 20 deletions test/sharness/t0010-basic-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,6 @@ test_expect_success "ipfs version --all has all required fields" '
grep "Golang version" version_all.txt
'

test_expect_success "ipfs help succeeds" '
ipfs help >help.txt
'

test_expect_success "ipfs help output looks good" '
egrep -i "^Usage" help.txt >/dev/null &&
egrep "ipfs <command>" help.txt >/dev/null ||
test_fsh cat help.txt
'

test_expect_success "ipfs help --help succeeds" '
ipfs help --help >help.txt
'

test_expect_success "ipfs help --help output looks good" '
egrep -i "^Usage" help.txt >/dev/null &&
egrep "ipfs <command>" help.txt >/dev/null ||
test_fsh cat help.txt
'

test_expect_success "'ipfs commands' succeeds" '
ipfs commands >commands.txt
'
Expand All @@ -71,6 +51,21 @@ test_expect_success "'ipfs commands' output looks good" '
grep "ipfs update" commands.txt
'

test_expect_success "All sub-commands accept help" '
echo 0 > fail
while read -r cmd
do
${cmd:0:4} help ${cmd:5} >/dev/null ||
{ echo "$cmd doesnt accept --help"; echo 1 > fail; }
echo stuff | $cmd --help >/dev/null ||
{ echo "$cmd doesnt accept --help when using stdin"; echo 1 > fail; }
done <commands.txt
if [ $(cat fail) = 1 ]; then
return 1
fi
'

test_expect_success "All commands accept --help" '
echo 0 > fail
while read -r cmd
Expand Down
10 changes: 0 additions & 10 deletions test/sharness/t0060-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ test_expect_success "ipfs help output looks good" '
test_fsh cat help.txt
'

test_expect_success "ipfs help --help succeeds" '
ipfs help --help >help.txt
'

test_expect_success "ipfs help --help output looks good" '
egrep -i "^Usage" help.txt >/dev/null &&
egrep "ipfs .* <command>" help.txt >/dev/null ||
test_fsh cat help.txt
'

# netcat (nc) is needed for the following test
test_expect_success "nc is available" '
type nc >/dev/null
Expand Down
4 changes: 0 additions & 4 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ test_expect_success "'ipfs name publish --help' succeeds" '
ipfs name publish --help
'

test_expect_success "'ipfs help name publish' succeeds" '
ipfs help name publish
'

test_launch_ipfs_daemon

test_expect_success "empty request to name publish doesn't panic and returns error" '
Expand Down

0 comments on commit 53fe9c9

Please sign in to comment.