Git Product home page Git Product logo

Comments (5)

chriscool avatar chriscool commented on September 3, 2024

Yeah, in general I would say that using test_cmp is probably more flexible, as it works for example with multi-line output, and more helpful when debugging as both the expected and actual ouputs are in some files and the diff is shown if the comparison fails.

I agree that it might not be as convenient as a special function though, but you might want to create one based on test_cmp. See for example https://github.com/git/git/blob/master/t/t6101-rev-parse-parents.sh#L10-L14 which contains:

test_cmp_rev_output () {
	git rev-parse --verify "$1" >expect &&
	eval "$2" >actual &&
	test_cmp expect actual
}

in your case you can create for example:

test_cmp_output () {
	echo "$1" >expect &&
	eval "$2" >actual &&
	test_cmp expect actual
}

and use that in your tests.

About the test_expect_equal_stdout you suggest, I wonder what the test description would be when the tests are run? Could you show how it would be implemented (maybe using the above test_cmp_output)?

See https://github.com/git/git/blob/master/t/t5001-archive-attr.sh#L9-L11 for an example of how such a function is implemented in Git.

Thanks!

from sharness.

chriscool avatar chriscool commented on September 3, 2024

In the case of the debian bug, I think the test could contain something like:

printf "%s\n" list quit | nc localhost munin | grep -v "^#" >all_plugins &&
sed "s/if_\w\+//g" all_plugins >all_plugins_wo_if &&
printf "%s\n" $(echo "cpu df df_inode entropy forks fw_packets interrupts irqstats load memory netstat open_files open_inodes proc_pri processes swap threads uptime users vmstat") >expected &&
test_cmp expected all_plugins_wo_if

See also #14 that I would like to work on soon.

from sharness.

sumpfralle avatar sumpfralle commented on September 3, 2024

Thank you for this hint - indeed this sounds like a good approach.
Just one detail: this would require the creation of temporary files in the current directory, which would need to be removed afterwards, or? How do you usually handle this?

from sharness.

chriscool avatar chriscool commented on September 3, 2024

Each test script is run in a directory named "trash directory.$script" where $script is the test script name (or some part of it). When a test fails this directory is not removed so one can cd into it and debug what happened.

For example if you modify one test in https://github.com/chriscool/sharness/blob/master/test/simple.t so that it fails, you will find a "trash directory.simple" directory.

When tests succeed, the directory is removed, so there is no need to clean up the temporary files.

from sharness.

sumpfralle avatar sumpfralle commented on September 3, 2024

Great - thank you!
In this case your proposed solution is indeed just the proper one - thus I think, there is no need for a new function.

from sharness.

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.