shspec/test/test-expect-core

108 lines
2.5 KiB
Bash

#!/bin/bash
# Core expectation tests
#
# Copyright (C) 2014 Mike Gewitz
#
# This file is part of shspec.
#
# shspec is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
describe succeed
it will succeed when command exits with status code 0
expect _expect--succeed 0 2
to succeed
end
it will fail when command exits with non-zero status code
expect _expect--succeed 1 2
to fail
end
end
describe fail
it will succeed when command exits with non-zero status code
expect _expect--fail 1 2
to succeed
end
it will fail when command exits with status code 0
expect _expect--fail 0 2
to fail
end
end
describe output
it will default to asserting against stdout
expect _expect--output 0 2 "test string" <<< "test string"
to succeed
end
it ignores exit code
expect _expect--output 1 2 "foo" <<< "foo"
to succeed
end
it fails on output mismatch
expect _expect--output 0 2 "foo" <<< "bar"
to fail
end
# as is good practice for Unix utilities
it expects trailing newline by default
expect _expect--output 0 2 "foo" < <( echo -n foo )
to fail
end
it can disable trailing newline check with "'without newline'" clause
expect _expect--output 0 2 "foo" without newline < <( echo -n foo )
to succeed
end
it errors on any unrecognized clause
expect _expect--output 0 2 "foo" fluffy bunnies <<< "foo"
to fail
end
end
describe match
it will default to asserting against stdout
expect _expect--match 0 2 "foo" <<< "foo"
to succeed
end
it ignores exit code
expect _expect--match 1 2 "foo" <<< "foo"
to succeed
end
it will perform partial match
expect _expect--match 0 2 "foo" <<< "contains foo"
to succeed
end
it will match against a pattern
expect _expect--match 0 2 "^foo.*baz" <<< "foo bar baz"
to succeed
expect _expect--match 0 2 "^foo.*baz" <<< "bar foo bar baz"
to fail
end
end