GithubHelp home page GithubHelp logo

assert.sh's People

Contributors

duksis avatar jwerle avatar lehmannro avatar macie avatar neerolyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assert.sh's Issues

refute function

Great project, and much needed. Have you ever considered supporting a "refute" function? It would allow you to test that a command returns anything BUT a certain value. Example:

#check that $count hasn't been defined as 1
refute "echo $count", 1

POSIX compatiblity

When writing turly portable shell scripts, one would resort to use the POSIX compatible subset, sh. However, the assert.sh script uses some bashisms, so it will not work in POSIX-compatible mode.

Reproduce the issue by running:

sh assert.sh # Will complain about redirects; probably due to the use of <<<

tests.sh does not run cleanly on Mac OS X

I'm not sure how tests.sh runs on other Mac OS X machines, but when I run it I get the following errors, none of them look to me like they should work on other Mac OS X systems.

Recreate:

git clone [email protected]:lehmannro/assert.sh.git assert.sh-framework
cd assert.sh-framework
./tests.sh

Output:

all 9 demo tests passed in 0.000s.
test #15 "_clean; skip_if 'cat /etc/passwd | grep $(echo $USER)';
assert_raises false; assert_end;" failed:
    expected "all 0 tests passed."
    got "test #1 "false" failed:\n  program terminated with code 1 instead of 0\n1 of 1 tests failed."
1 of 15 output tests failed in 0.000s.
test #11 "shopt -o errexit" failed:
    program terminated with code 1 instead of 0
1 of 15 interaction tests failed in 1.000s.
test #10 "echo -n %s | wc -c" failed:
    expected "2"
    got "       2"
1 of 11 regression tests failed in 0.000s.
  • Test 15 is because the current user on Mac OS X is unlikely to be in /etc/passwd because regular users aren't stored in there but in its Open Directory service.
  • Test 11 - I have no idea.
  • Test 10 is I guess because Mac OS's wc is the BSD version and not the gnu version, and the output seems to differ with the BSD version.

(I tried both master branch and v1.1 tag).

Tests are run even if `bc` is not installed

Here is my test file for mvb:

#! /bin/bash

. assert.sh

# `mvb a b` should fail if 'b' doesn't exist
assert_raises 'mvb a b' 1

# `mvb a b` should rename 'b' to 'a'
touch b
assert_raises 'mvb a b' 0
assert_raises '[ -f a ]' 0
rm a

# `mvb a b/` should mv 'b/a' in 'a'
mkdir b
touch b/a
assert_raises 'mvb a b/' 0
assert_raises '[ -f a ]' 0
rm a
rmdir b

assert_end 'mvb'

I tested on Travis and bc is not installed by default, here is the (end of the) log:

$ cd tests;bash ./tests.sh
assert.sh: line 81: bc: command not found
all 5 mvb tests passed in s.

�The command "bash ./tests.sh" exited with 0.�

Done. Your build exited with 0.

Generate JUnit XML

Would be awesome to optionally get a JUnit XML test report at the end.

Any suggestions as to how that could best be accomplished?

CI build failed!

I add some doc lines, but CI tell me that build failed. (#21)

Which state of this project? Is it supported?

Incorrect name in package.json

Hey dude, GitHub have a dependency management bit, and it's showing up incorrectly due to how it gets information between npm and GitHub. Your name in the package.json is assert, but that's already an npm package, so GitHub is getting super confused.

Can you remove the name field from your package.json file. I'd recommend using make or another build tool instead of npm for non-node repos.

The image below shows that there are repos with your dependency, but actually they are depending on commonjs-assert, which is what is actually aliased to that name in NPM.

Screenshot 2019-03-25 at 11 58 50

https://www.npmjs.com/package/assert <- this is what you are saying your repo is

Cheers.

assert.sh: line 87: DISCOVERONLY: unbound variable

Looks like a nice lightweight tool.

But there is always a but :-)

The script I want to test has this line:
set -u
to protect me against uninitialized variables.

Unfortunately DISCOVERONLY seems to be one such and it cause assert to crash.

Question about project stability

Is this project still maintained and stable? Last commit on master branch was 10 months ago and build on Travis CI failing from that time. I would like to use this project, but I'm not sure about its stability.

assert_contains function

Hi Robert.

Here's the assert_contains() function I wrote for regex matching.

Usage is: assert_contains "str" "regex" [0|1], where 0=expected match, 1=nomatch

assert_contains() {
# assert_contains [expected](%28 tests_ran++ %29) || :
[[ -n "$DISCOVERONLY" ]] && return || true
str=${1:-}
regex=${2:-}
expected=${3:-0}

# status = 0 match, 1 = no match
status=1

# try the match. there's 3 possible outcomes:
#
#1) it may succeed and be captured if user specified parentheses: status=0 and match="something"
#2) it may succeed and not be captured if parentheses not used: status=0 and match=""
#3) it may fail to match: status=1 and match=""

match=""
if [[ $str =~ $regex ]]; then
    status=0
    match=${BASH_REMATCH[1]} # maybe some kind of capture is available
fi

if [[ "$status" -eq "$expected" ]]; then
    [[ -n "$DEBUG" ]] && echo -n . || true
    return
fi

if [ $status -eq 0 ] && [ -z "$match" ]; then
   if [[ $str =~ ($regex) ]]; then # the previous regex succeeded but no capture in $match, so try again with capturing parenthesess for debugging
      match=${BASH_REMATCH[1]}
   fi
fi

_assert_fail "match terminated with code $status and match '$match' instead of $expected" "$str" "$expected"

}

bc isn't listed as a requirement

bc is currently used to calculate test time, but the installation instructions say that only sourcing assert.sh is required. The instructions should be updated to ensure people install bc.

How to test stderr?

Could you give any advice on how to test stderr? E.g. for assert_raises I'd love to assert on some expected error message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.