jtplaarj / IceCream-Bash

Never use echo to debug again

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub

IceCream-bash - Never use echo to debug again

Overview

Simple implementation of IceCream for Bash.

  • This project aims to:
    • Print the value of a variable as well as the position in the program.
    • Work with normal variables, arrays and associative arrays (only values are printed, not keys).

An example output from the test file 1 is:

(./test_file_1.sh,main) 16: test_a - string
(./test_file_1.sh,main) 17: test_a - string
(./test_file_1.sh,main) 18: test_b - string_a string_b string_c
(./test_file_1.sh,main) 19: test_b - string_a string_b string_c
(./test_file_1.sh,main) 20: test_c - 5
(./test_file_1.sh,main) 21: test_c - 5
(./test_file_1.sh,main) 22: test_d - stringab string_aa
(./test_file_1.sh,main) 23: test_d - stringab string_aa

How do I use it?

Requirements

This script has been tested in Bash v5. Comments about issues in other versions are welcomed.

Installation

There are two ways to include this commands in your script:

  1. Source ic.sh in your script:
source ic.sh
  1. Just copy the content of the script to your script.

Usage

This project provides two different commands:

  1. ic prints the line, file name, function name, name of variable and value.
  2. ict prints all the call tree.
  3. The icp and ictp variants just print a message string, with similar line preambles.

The usage in both cases is the same:

variable="hello"
ict variable
ic variable

Several examples can be found in the test subdir.

Test

There is a test suite with example. It has been done using the Bats-core testing framework for Bash.

IceCream in Other Languages

Delicious IceCream should be enjoyed in every language.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

About

Never use echo to debug again

License:MIT License


Languages

Language:Shell 100.0%