Updated for new curriculum - Please let me know if there are any issues or bugs with the new release.
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.
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.
Requires PHP. All 42 lab computers should have PHP installed. See also Compatibility with Other Systems.
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.
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 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.
./test sruns all the tests that start with a string, in this case 's'. As you might guess, the%stests start with 's'. Tests for the other specifiers (%d,%f, etc.) can be selected the same way../test 42runs test #42./test 42 84runs all the enabled tests from #42 to #84./testruns all the enabled tests./test helpshows 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.
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 sDisables all tests that start with 's'./enable-test nocrashEnables all tests that start with 'nocrash'./disable-test 42 84Disables all tests from #42 to #84./disable-test && ./enable-test sDisables 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.
Debugger compatibility mode ( -d ) is automatically turned on for single tests:
lldb ./test 42
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.
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.
Feel free to contribute tests for these:
- Size modifiers
t,z,j, andq. %n'(thousands separator flag)$for dynamic precision. ($for argument selection is covered underargnum_)
*(There are some tests, but not many combinations with other flags)%g,%e,%a(some tests exist in themoulblock, but they are not rigorously tested with flag combinations like the other tests)
The full documentation is available in the Wiki. Here are some quick links:
- Installation
- Usage
- What's Not Covered
- Workflow with PFT
- Options and Configuration
- Additional Features
- Troubleshooting
- Compatibility With Other Systems
- Contributing to this repo (and possible future features)
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
By default, PFT collects some usage statistics on every make. The full list of data collected is:
- A SHA-1 hash of your
whoamiusername. - Whether you're on the Fremont, Paris, or Moscow campus, or your
hostnameif none of those. - Whether it is a first install or a re-make.
- The name of your configuration (
CONFIG_NAMEin 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.
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: