Code Monkey home page Code Monkey logo

Comments (2)

kward avatar kward commented on August 31, 2024 3

I'm guessing that all you are missing is the need to shift all the command-line arguments off the stack before calling shunit2.

The following test code (saved as test_date_cmd.sh) demonstrates what I'm talking about. Notice the shift $# line just before shunit2 is called.

#!/bin/bash

# Echo any provided arguments.
[ $# -gt 0 ] && echo "#:$# 1:$1 2:$2 3:$3"

test_date_cmd() {
  ( date '+%a' >/dev/null 2>&1 )
  local rtrn=$?
  assertTrue "unexpected date error; ${rtrn}" ${rtrn}
}

# Eat all command-line arguments before calling shunit2.
shift $#
. ~/lib/sh/shunit2

Running the command without arguments:

$ ./test_date_cmd.sh 
test_date_cmd

Ran 1 test.

OK

Running the same command with arguments:

$ ./test_date_cmd.sh a b c
#:3 1:a 2:b 3:c
test_date_cmd

Ran 1 test.

OK

from shunit2.

dminca avatar dminca commented on August 31, 2024

So you want to test calling your script with some params? Is that what you're trying to achieve?

from shunit2.

Related Issues (20)

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.