From ce17200e1e2764c79f78b3b1fe140afb7a09b6d0 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 28 Apr 2020 16:32:27 -0300 Subject: [PATCH] Revert "Migrate expect based test script to bats" This reverts commit ac87c23dbc3880c9260bd74f37e901f3878d017f. This change has to be in another PR, as per https://github.com/bisq-network/bisq/issues/4198#issuecomment-620133527 --- cli/test.sh | 201 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 139 insertions(+), 62 deletions(-) diff --git a/cli/test.sh b/cli/test.sh index 25432a36209..046cbd910aa 100755 --- a/cli/test.sh +++ b/cli/test.sh @@ -1,79 +1,156 @@ -#!/usr/bin/env bats +#!/bin/bash # -# bats v0.4.0 project +# References & examples for expect: # -# https://github.com/sstephenson/bats/tree/v0.4.0 +# - https://pantz.org/software/expect/expect_examples_and_tips.html +# - https://stackoverflow.com/questions/13982310/else-string-matching-in-expect +# - https://gist.github.com/Fluidbyte/6294378 +# - https://www.oreilly.com/library/view/exploring-expect/9781565920903/ch04.html # # Prior to running this script, run: # # ./bisq-daemon --apiPassword=xyz # -# To run this script: -# -# cd -# bats cli/bats-test.sh -# # The data directory used must contain an unencrypted wallet with a 0 BTC balance -@test "test unsupported method error" { - run ./bisq-cli --password=xyz bogus - [ "$status" -eq 1 ] - echo "actual output: $output" >&2 # printed only on test failure - [ "$output" = "Error: 'bogus' is not a supported method" ] -} +# Ensure project root is the current working directory +cd $(dirname $0)/.. + +OUTPUT=$(expect -c ' + # exp_internal 1 + puts "TEST unsupported cmd error" + set expected "Error: '\''bogus'\'' is not a supported method" + spawn ./bisq-cli --password=xyz bogus + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test unrecognized option error" { - run ./bisq-cli --bogus getversion - [ "$status" -eq 1 ] - echo "actual output: $output" >&2 - [ "$output" = "Error: bogus is not a recognized option" ] -} +OUTPUT=$(expect -c ' + puts "TEST unrecognized option error" + set expected "Error: bogus is not a recognized option" + spawn ./bisq-cli --bogus getversion + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test missing required password option error" { - run ./bisq-cli getversion - [ "$status" -eq 1 ] - echo "actual output: $output" >&2 - [ "$output" = "Error: missing required 'password' option" ] -} +OUTPUT=$(expect -c ' + # exp_internal 1 + puts "TEST missing required password option error" + set expected "Error: missing required '\''password'\'' option" + spawn ./bisq-cli getversion + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test incorrect password error" { - run ./bisq-cli --password=bogus getversion - [ "$status" -eq 1 ] - echo "actual output: $output" >&2 - [ "$output" = "Error: incorrect 'password' rpc header value" ] -} +OUTPUT=$(expect -c ' + # exp_internal 1 + puts "TEST getversion (incorrect password error)" + set expected "Error: incorrect '\''password'\'' rpc header value" + spawn ./bisq-cli --password=bogus getversion + expect { + $expected { puts "PASS\n" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test getversion call with quoted password" { - run ./bisq-cli --password="xyz" getversion - [ "$status" -eq 0 ] - echo "actual output: $output" >&2 - [ "$output" = "1.3.2" ] -} +OUTPUT=$(expect -c ' + # exp_internal 1 + puts "TEST getversion (password value in quotes)" + set expected "1.3.2" + # Note: have to define quoted argument in a variable as "''value''" + set pwd_in_quotes "''xyz''" + spawn ./bisq-cli --password=$pwd_in_quotes getversion + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test getversion" { - run ./bisq-cli --password=xyz getversion - [ "$status" -eq 0 ] - [ "$output" = "1.3.2" ] -} +OUTPUT=$(expect -c ' + puts "TEST getversion" + set expected "1.3.2" + spawn ./bisq-cli --password=xyz getversion + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test getbalance (available & unlocked wallet with 0 btc balance)" { - run ./bisq-cli --password=xyz getbalance - [ "$status" -eq 0 ] - [ "$output" = "0.00000000" ] -} +OUTPUT=$(expect -c ' + puts "TEST getbalance" + # exp_internal 1 + set expected "0.00000000" + spawn ./bisq-cli --password=xyz getbalance + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test help displayed on stderr if no options or arguments" { - run ./bisq-cli - [ "$status" -eq 1 ] - [ "${lines[0]}" = "Bisq RPC Client" ] - [ "${lines[1]}" = "Usage: bisq-cli [options] " ] - # TODO add asserts after help text is modified for new endpoints -} +OUTPUT=$(expect -c ' + puts "TEST running with no options or arguments prints help text" + # exp_internal 1 + set expected "Bisq RPC Client" + spawn ./bisq-cli + expect { + $expected { puts "PASS" } + default { + set results $expect_out(buffer) + puts "FAIL expected = $expected" + puts " actual = $results" + } + } +') +echo "$OUTPUT" +echo "========================================================================" -@test "test --help option" { - run ./bisq-cli --help - [ "$status" -eq 0 ] - [ "${lines[0]}" = "Bisq RPC Client" ] - [ "${lines[1]}" = "Usage: bisq-cli [options] " ] - # TODO add asserts after help text is modified for new endpoints -} +echo "TEST --help option prints help text" +./bisq-cli --help