Skip to content
/ pft Public
forked from gavinfielder/pft

For the 42 project ft_printf, a regression testing utility and unit test library.

Notifications You must be signed in to change notification settings

appinha/pft

 
 

Repository files navigation

Updated for new curriculum - Please let me know if there are any issues or bugs with the new release.

PFT

This is a unit test library and configurable tester for the 42 project ft_printf.

By default, it can check if your completed printf is pretty good or not pretty good.

It's more useful as a production tool while you're developing ft_prinf, because it lets you enable and disable entire blocks of tests at once, search and run tests by name, category, and previous run history, and in general perform quick regression testing. It's quick and easy to add your own tests, which I recommend on principle. It's built to be flexible and highly configurable, so you can use it how you wish.

Requirements

You have to have a Makefile in your project directory that will compile libftprintf.a as the default make option, and your libftprintf.a has to have ft_printf inside.

Other than this, it should be completely general to all ft_printf projects.

System Requirements (for computers outside the lab)

Requires PHP. All 42 lab computers should have PHP installed. See also Compatibility with Other Systems.

Installation

In the root of your repo, run this command:

git clone https://github.com/gavinfielder/pft.git pft && echo "pft/" >> .gitignore

For most users, that is all that is required.

If you are running on Linux

Change INCLUDE_LIBPTHREAD=0 in options-config.ini to INCLUDE_LIBPTHREAD=1.

This could apply to other systems--if you get a make error with undefined refrences to pthread_ functions, make this change and it will work.

If your libft.a is separate from libftprintf.a

If you include all required .o files (including your libft) in libftprintf.a, this is not necessary. If you do NOT, and require your libft separate, you must set USE_SEPARATE_LIBFT=1 in options-config.ini, and make sure the path is correct. See options-config.ini, and it should be self-explanatory.

For non-standard installation options, see Installation.

Usage

  • ./test s runs all the tests that start with a string, in this case 's'. As you might guess, the %s tests start with 's'. Tests for the other specifiers (%d, %f, etc.) can be selected the same way.
  • ./test 42 runs test #42
  • ./test 42 84 runs all the enabled tests from #42 to #84
  • ./test runs all the enabled tests
  • ./test help shows examples and other help information.

You can also run specific types of tests by using Wildcard Search. See also Test Naming Conventions.

When you fail a test, the file results.txt will show the results of the test including the first line of code for the test (most of them are one line anyway), the return values, what printf printed, and what ft_printf printed.

Enabling and Disabling tests

I have provided scripts that make it easy to enable and disable tests. These scripts accept the same queries as the ./test executable.

  • ./disable-test s Disables all tests that start with 's'
  • ./enable-test nocrash Enables all tests that start with 'nocrash'
  • ./disable-test 42 84 Disables all tests from #42 to #84
  • ./disable-test && ./enable-test s Disables all tests except tests that start with 's'.

You can call ./enable-test (with no arguments) to enable all tests, but keep in mind that some tests are disabled by default because if you have not implemented certain bonuses, your ft_printf will segfault.

Using PFT with LLDB or other debuggers

Debugger compatibility mode ( -d ) is automatically turned on for single tests:

lldb ./test 42

Known Issues

The 2020 update added * tests to the required features. Tests were added from https://github.com/cclaude42/PFT_2019, but these tests don't include enough combinations with other flags--looking for current 42 students to add such tests.

Fork mode (-x) used in conjunction with IGNORE_RETURN_VALUE=0 is currently not properly reporting expected return value in results.txt for many tests (issue #11). This bug does not affect the pass/fail result of a test. Running in non-fork mode (-X) will show the correct return values. The default configuration has been set to IGNORE_RETURN_VALUE=1. If this issue might affect you, a warning will be printed in results.txt.

How it works, in Brief

The Makefile creates two versions of each unit test function, one that uses ft_printf, and one that uses printf. For each test, it redirects stdout to a file, calls the function. Once each version returns, it opens both files and reads each one byte by byte until both reach EOF. If any single byte differs, the test fails.

What's NOT Covered

Feel free to contribute tests for these:

  • Size modifiers t, z, j, and q.
  • %n
  • ' (thousands separator flag)
  • $ for dynamic precision. ($ for argument selection is covered under argnum_)

What's not covered very well

  • * (There are some tests, but not many combinations with other flags)
  • %g, %e, %a (some tests exist in the moul block, but they are not rigorously tested with flag combinations like the other tests)

Other Documentation

The full documentation is available in the Wiki. Here are some quick links:

Todo List for the Unit Test Library

I occasionally get suggestions for the unit test library. I keep this list to keep track of what I want to do the next time I modify unit_tests.c
Todo List for the Unit Test Library

Usage Statistics

By default, PFT collects some usage statistics on every make. The full list of data collected is:

  • A SHA-1 hash of your whoami username.
  • Whether you're on the Fremont, Paris, or Moscow campus, or your hostname if none of those.
  • Whether it is a first install or a re-make.
  • The name of your configuration (CONFIG_NAME in options-config.ini)

You can disable this behavior in options-config.ini, and/or see exactly what the script does in src/usage_statistics.php. My reason in doing this is to have real usage data to show recruiters and hiring managers. If you're a 42 student and want to know more or see the collected data, feel free to message me on slack.

Credits

The test method itself was adapted from outdated moulinette test files a buddy gave me, from which the author was ly@42.fr. The vast majority of code was written by me. The tests prefixed moul_ were adapted from the moulinette test files, the tests with _ftfc_ were adapted from 42FileChecker. The vast majority of tests were written by me; some tests were contributed by phtruong, akharrou, and robbie. Big thanks to cclaude for doing the first update for the new curriculum.

Also thanks to:

About

For the 42 project ft_printf, a regression testing utility and unit test library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 93.0%
  • PHP 3.5%
  • Shell 2.7%
  • Makefile 0.8%