Skip to main content

A very-simple-subset-of-haskell fuzzer

Project description

A very-simple-subset-of-haskell fuzzer. With the ability to generate lexical tokens as well as plain code.

```
module Generated (function0,function1,function2) where

function0 :: Int -> Bool -> Bool -> Bool -> Bool -> Int -> Int
function0 a b c d e f = (function1 (2 /= 7) False False)

function1 :: Bool -> Bool -> Bool -> Int
function1 a b c = (8 * 0)

function2 :: Bool -> Int
function2 a = 1
```

it's available on pip by `pip install huzzer` (python3+ only)

## Using `huzzer`

The easiest way to use `huzzer` is from the command line:

```
>>>>> huzz
module Generated (function0,function1,function2) where

function0 :: Bool -> Bool
function0 a = ((function2 4 (0 >= 5)) <= ((mod 8 9) + (1 - (function2 0 a))))

function1 :: Bool -> Int -> Int -> Bool -> Bool
function1 a b c d = ((a && a) && (function0 (function1 True b c d)))

function2 :: Int -> Bool -> Int
function2 a b = (div (function2 (max a a) b) 3)
```

There are some options to vary the complexity of programs:
```bash
>>>>> huzz -h
Huzz.

Usage:
huzz [--seed=<randomseed>] [--max-args=<maxarglen>] [--expr-depth=<exprdepth>]
huzz -h | --help

Options:
-h --help Show this screen.
-s --seed=<randomseed> Use <randomseed> to initialise RNG.
-a --max-args=<maxarglen> Maximum number of arguments a function can have [default: 8].
-e --expr-depth=<exprdepth> Maximum expression depth [default: 6].
```

### Using From Inside Python

```python
from huzzer.huzz import huzzer
from huzzer.tokenizing import tokenize

seed = 1337

random_haskell_code = huzzer(
seed,
max_expression_depth=4,
max_type_signiature_length=5,
max_number_of_functions=3,
)


tokens = tokenize(random_haskell_code)

non_whitespace_token_ids = [x.type for x in tokens if x.channel == 0]

print(random_haskell_code)
print('======================')
print(non_whitespace_token_ids)

```
```sh
module Generated (function0,function1,function2) where

function0 :: Bool -> Int -> Bool -> Bool -> Bool
function0 a b c d = ((function1 9) && (function0 d 1 d (function0 c b d d)))

function1 :: Int -> Bool
function1 a = (False || True)

function2 :: Bool -> Int -> Bool -> Bool -> Bool
function2 a b c d = (function2 True 9 False c)
======================
[1, 2, 51, 16, 4, 17, 4, 18, 52, 3, 53, 16, 5, 37, 6, 38, 6, 37, 6, 37, 6, 37, 53, 16, 8, 9, 10, 11, 7, 51, 51, 17, 48, 52, 36, 51, 16, 11, 40, 11, 51, 16, 10, 9, 11, 11, 52, 52, 52, 53, 17, 5, 38, 6, 37, 53, 17, 8, 7, 51, 50, 35, 49, 52, 53, 18, 5, 37, 6, 38, 6, 37, 6, 37, 6, 37, 53, 18, 8, 9, 10, 11, 7, 51, 18, 49, 48, 50, 10, 52]

```



## Setup
Make sure you have python3 on your machine (`which python3` should print a path to it).

Set up a `virtualenv` with `virtualenv -p \`which python3\` env`

Activate the environment with `source env/bin/activate`

Install requirements `pip install -r requirements.txt`

Then you should be good to go. To leave the virtualenv, type `deactivate`


## Testing
To run all of the tests, run `nosetests`.

To run larger acceptance tests (against the ghc compiler), you will need `ghc` and `parallel` installed.
run `./large_acceptance_test.sh <number of tests>`

## TODOs
* multiple definitions for functions

### Distribution
```
python setup.py sdist bdist_wheel
twine upload dist/*
```


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huzzer-0.1.2.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

huzzer-0.1.2-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file huzzer-0.1.2.tar.gz.

File metadata

  • Download URL: huzzer-0.1.2.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for huzzer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2f4f7912263f66ac6f5b9b641f105e69d4f41da8684e90a728ce4c2b5ed9178e
MD5 d77460bcb1ebc29a9f3699a26301b067
BLAKE2b-256 f9c6655336e5e9b92d09ac1a18f535b9c406c4b16d764cdb459ef0ce9f1a38ef

See more details on using hashes here.

File details

Details for the file huzzer-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for huzzer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54a0ecfd1c08d7c280cc752d0a4a4cff73bf2928c42f2620c64a7ecf3c0da033
MD5 05689d89f547d6990e468fae6cea8ab6
BLAKE2b-256 dc6d45f411c332ed0a6fbb8ee9d3a015618b4fb512bad238e9c160c35834414b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page