Giter Site home page Giter Site logo

robotc-tap's Introduction

robotc-tap

Test Anything Protocol for RobotC. Basically a bunch of unit test helper functions, that outputs to the debug stream.

How To

  1. Click Download Zip.
  2. Copy the tap.c file to the directory that you want to test.
  3. Create a unit test file, maybe test.c, or run_Tests.c.
  4. In the file, write #include "tap.c".
  5. Use the Functions provided.
  6. Compile and run your unit test file.

Example

#include "tap.c"

task main() {

	tTest("the test suite works");
		tOk(true);
		tNotOk(false, "not ok ever!");
		tEqual(17, 83-66, "83-56=17");
		tNotEqual(10, 100, "ten ain't a hundred!");
		tPass("oh yes");

	tTest("this is the second test");
		tFail("failing # TODO make this not fail");
		tFail("skipping # SKIP make this skip");

	tTest("the test suite works");
		tEqual(17, 17, "17=17");
		tEqual(10, 10, "ten ain't a hundred!");
		tPass("such win");
	tEnd(); //Only run this at the end
}

Functions

For a quick and dirty namespace solution, internal global variables and functions start with "_", and user functions start with "t" (for test).

tTest(string msg)

This starts a new set of tests, and resets some internal counters. This also ends the previous set of tests, if there was one.

Code:

tTest("my function is awesome");

Output:

# my function is awesome

tOk(bool test, string message)

This checks if test is true.

Code:

tOk(bLcdBacklight, "the backlight is on");

Output:

ok 1 the backlight is on

tNotOk(bool test, string message)

This checks if test is false.

Code:

tNotOk(bLcdBacklight, "the backlight is off");

Output:

ok 2 the backlight is off

tEqual(int test, int expected, string message)

This checks if test equals expected.

Code:

tEqual(motor[MY_MOTOR], 127, "MY_MOTOR is running full speed.");

Output:

ok 3 MY_MOTOR is running full speed.

tNotEqual(int test, int unexpected, string message)

This checks if test does not equal unexpected.

Code:

tNotEqual(motor[MY_MOTOR2], 0, "MY_MOTOR is not still");

Output:

ok 4 MY_MOTOR2 is not still

tPass(string message)

This is a test that always passes.

Code:

tPass("yay this works")

Output:

ok 5 yay this works

tFail(string message)

This is a test that always fails.

Code:

tFail("that was predictable")

Output:

not ok 6 that was predictable
  ---
  got: 0
  expected: 1
  ...

tEnd(string message)

This ends the last set of tests. Use tTest() to end any set that isn't last.

License

MIT

robotc-tap's People

Contributors

artskydj avatar

Stargazers

Alex Wang avatar

Watchers

James Cloos avatar  avatar  avatar

robotc-tap's Issues

Question on running tests

Hi Joseph, I'm interested in using this package to run tests for my robotC programs. I am new to RobotC, and as such, I have a few questions regarding how this works

  1. Is it possible to run these tests locally on the computer before having to deploy to the robot? If so, how can I do this? My goal is to avoid having to spend time deploying the code to the robot to find out the test results.

  2. If I take your example code and remove the calls to tFail(), I get a warning in RobotC that says "Unreferenced function tFail" when I compile the code. Should I be concerned about that? If so, how can I avoid this warning if I don't need to assert for failure?

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.