Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating andreas branch #272

Merged
merged 50 commits into from
Jan 15, 2025
Merged
Changes from 14 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8322046
Merge pull request #172 from fandango-fuzzer/main
joszamama Dec 17, 2024
5b7a5b2
adding tests, progress on #173
TimScheckenbach Dec 17, 2024
8f04f7f
more tests, started fixing bug
TimScheckenbach Dec 19, 2024
52e1f3f
fixed test, fixed #188 but not allowing <foo>[0][0]
TimScheckenbach Jan 7, 2025
09b2176
removed debug statements
TimScheckenbach Jan 7, 2025
4694485
more tests #173
TimScheckenbach Jan 7, 2025
74de8b7
fix: dependency issues
joszamama Jan 14, 2025
cdb3108
Merge pull request #252 from fandango-fuzzer/andreas
joszamama Jan 14, 2025
3d82d87
Merge pull request #253 from fandango-fuzzer/dev
joszamama Jan 14, 2025
11a7dae
Create SECURITY.md
joszamama Jan 14, 2025
08dc731
Merge pull request #254 from fandango-fuzzer/joszamama-patch-1
joszamama Jan 14, 2025
a87df23
fix: typo in readme
joszamama Jan 14, 2025
7c1037c
Merge pull request #255 from fandango-fuzzer/dev
joszamama Jan 14, 2025
5ef2f69
feat: status badges
joszamama Jan 14, 2025
18c0d40
Merge pull request #256 from fandango-fuzzer/dev
joszamama Jan 14, 2025
150298b
test: book url
joszamama Jan 14, 2025
95c8019
Merge pull request #257 from fandango-fuzzer/dev
joszamama Jan 14, 2025
ee727c8
test: book url
joszamama Jan 14, 2025
90d0c8e
Merge pull request #258 from fandango-fuzzer/dev
joszamama Jan 14, 2025
cee5954
test: book url
joszamama Jan 14, 2025
f51546a
test: book url
joszamama Jan 14, 2025
8b6361e
Merge pull request #259 from fandango-fuzzer/dev
joszamama Jan 14, 2025
c51bda1
test: book url
joszamama Jan 14, 2025
a262c55
Merge pull request #260 from fandango-fuzzer/dev
joszamama Jan 14, 2025
374ac50
test: book url
joszamama Jan 14, 2025
9a9b71b
Merge pull request #261 from fandango-fuzzer/dev
joszamama Jan 14, 2025
1e88f35
test: book url
joszamama Jan 14, 2025
2db1e60
test: book url
joszamama Jan 14, 2025
efd926f
Merge pull request #262 from fandango-fuzzer/dev
joszamama Jan 14, 2025
0f73c82
test: book url
joszamama Jan 14, 2025
e5d4b48
Merge pull request #263 from fandango-fuzzer/dev
joszamama Jan 14, 2025
71ddbfe
test: book url
joszamama Jan 14, 2025
ec59a42
Merge pull request #264 from fandango-fuzzer/dev
joszamama Jan 14, 2025
eb51bb3
Merge pull request #265 from fandango-fuzzer/dev
joszamama Jan 14, 2025
c2fcf48
test: book url
joszamama Jan 14, 2025
44fcc6c
test: book url
joszamama Jan 14, 2025
93b8135
Merge pull request #266 from fandango-fuzzer/dev
joszamama Jan 14, 2025
94a882e
test: book url
joszamama Jan 14, 2025
f3b8a47
test: book url
joszamama Jan 14, 2025
5a2c7ef
Merge pull request #267 from fandango-fuzzer/dev
joszamama Jan 14, 2025
a4e2f4e
feat: new release
joszamama Jan 15, 2025
658fdbe
Merge pull request #268 from fandango-fuzzer/dev
joszamama Jan 15, 2025
586adfd
Merge pull request #269 from fandango-fuzzer/main
joszamama Jan 15, 2025
c3f37f2
fix: parser rollback
joszamama Jan 15, 2025
454c710
clean: up repo
joszamama Jan 15, 2025
28a10fe
Merge branch 'dev' into tim
joszamama Jan 15, 2025
8eaa6a7
Merge pull request #270 from fandango-fuzzer/tim
joszamama Jan 15, 2025
69b9693
fix: python tests
joszamama Jan 15, 2025
5927996
fix: graphviz missing
joszamama Jan 15, 2025
2a2535b
Merge pull request #271 from fandango-fuzzer/dev
joszamama Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/deploy-book.yml
Original file line number Diff line number Diff line change
@@ -26,40 +26,46 @@ jobs:
with:
python-version: 3.13

# Step 3: Install dependencies
# Step 3: Ensure Graphviz system package is installed
- name: Install Graphviz system package
run: |
sudo apt-get update
sudo apt-get install -y graphviz
# Step 4: Install dependencies
- name: Install dependencies
run: |
pip install -e .
pip install jupyter-book pyppeteer ghp-import black
pip install jupyter-book pyppeteer ghp-import black graphviz
# Step 4: Locate Fandango and add to PATH
# Step 5: Locate Fandango and add to PATH
- name: Locate Fandango and add to PATH
run: |
which fandango
echo "/opt/hostedtoolcache/Python/3.13.1/x64/bin/fandango" >> $GITHUB_PATH
fandango --help
# Step 5: Build the documentation
# Step 6: Build the documentation
- name: Build the book
run: |
jupyter-book build docs
# Step 6: Clone the target repository
# Step 7: Clone the target repository
- name: Clone the target repository
run: |
git clone https://github.com/fandango-fuzzer/fandango-fuzzer.github.io.git gh-pages
# Step 7: Copy the built HTML files to the target repository
# Step 8: Copy the built HTML files to the target repository
- name: Copy built files to the target repository
run: |
cp -r docs/_build/html/* gh-pages/
# Step 8: Commit and push changes to the target repository
# Step 9: Commit and push changes to the target repository
- name: Deploy to GitHub Pages
run: |
cd gh-pages
git config --global user.name "${{ secrets.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ secrets.CI_COMMIT_EMAIL }}"
git add .
git commit -m "Update GitHub Pages site" || echo "No changes to commit"
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/fandango-fuzzer/fandango-fuzzer.github.io.git main
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/fandango-fuzzer/fandango-fuzzer.github.io.git main
5 changes: 5 additions & 0 deletions tests/resources/bar.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<start> ::= <foo>* := test();
<foo> ::= "a" | "b" | "c" | "r";

def test():
return "bar"
5 changes: 5 additions & 0 deletions tests/resources/children.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<start> ::= <number>;
<number> ::= <digit> | <digit><number>;
<digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0";

int(<start>.<number>.<digit>) == 0;
3 changes: 3 additions & 0 deletions tests/resources/digit.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<start> ::= <digit>+;
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
5 changes: 5 additions & 0 deletions tests/resources/indirect_children.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<start> ::= <number>;
<number> ::= <digit> | <digit><number>;
<digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0";

int(<start>..<digit>) == 1;
2 changes: 2 additions & 0 deletions tests/resources/min_reps.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<start> ::= <a>{3, };
<a> ::= "a";
2 changes: 2 additions & 0 deletions tests/resources/repetitions.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<start> ::= <a>{3};
<a> ::= "a";
2 changes: 2 additions & 0 deletions tests/resources/slicing.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<start> ::= <a>{3, 10};
<a> ::= "a";
106 changes: 106 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import unittest
import subprocess
import os

from fandango.cli import get_parser


class test_cli(unittest.TestCase):

def run_command(self, command):
proc = subprocess.Popen(command,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
)
out, err = proc.communicate()
return out.decode(), err.decode(), proc.returncode



def test_help(self):
command = ["fandango", "--help"]
out, err, code = self.run_command(command)
parser = get_parser(True)
self.assertEqual(0, code)
self.assertEqual(out, parser.format_help())
self.assertEqual(err, "")

def test_fuzz_basic(self):
command = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912"]
expected = """35716
4
9768
30
5658
5
9
649
20
41"""
out, err, code = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual(expected, out.strip())
self.assertEqual("", err)

def test_output_to_file(self):
command = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912", "-o", "tests/resources/test.txt", "-s", ";"]
expected = "35716;4;9768;30;5658;5;9;649;20;41;"
out, err, code = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual("", out)
self.assertEqual("", err)
with open("tests/resources/test.txt", "r") as fd:
actual = fd.read()
os.remove("tests/resources/test.txt")
self.assertEqual(expected, actual)

def test_output_multiple_files(self):
command = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912", "-d", "tests/resources/test"]
expected = ["35716","4","9768","30","5658","5","9","649","20","41"]
out, err, code, = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual("", out)
self.assertEqual("", err)
for i in range(10):
filename = "tests/resources/test/fandango-" + str(i+1).zfill(4) + ".txt"
with open(filename, "r") as fd:
actual = fd.read()
self.assertEqual(expected[i], actual)
os.remove(filename)
os.rmdir("tests/resources/test")

def test_command_line_constraints(self):
command_single = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912", "-c", "25 <= int(<start>) and int(<start>) <= 45"]
expected = """30
41
29
44
44
36
28
30
41
29
"""
out, err, code = self.run_command(command_single)
self.assertEqual(0, code)
self.assertEqual(expected, out)
self.assertEqual("", err)
command_multiple = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912", "-c", "25 <= int(<start>)", "-c", "int(<start>) <= 45"]
out, err, code = self.run_command(command_multiple)
self.assertEqual(0, code)
self.assertEqual(expected, out)
self.assertEqual("", err)

def test_unsat(self):
command = ["fandango", "fuzz", "-f", "tests/resources/digit.fan", "-n", "10", "--random-seed", "426912", "-c", "False"]
expected ="""fandango:ERROR: Population did not converge to a perfect population
fandango:ERROR: Only found 0 perfect solutions, instead of the required 10
"""
out, err, code = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual("", out)
self.assertEqual(expected, err)



58 changes: 58 additions & 0 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
@@ -343,6 +343,64 @@ def test_exists_constraint(self):
)
self.assertTrue(constraint.check(example))

def test_direct_children(self):
constraint = self.get_constraint("str(<start>.<ab>) == 'a';")
counter_example = DerivationTree(
NonTerminal("<start>"),
[
DerivationTree(
NonTerminal("<ab>"),
[
DerivationTree(
Terminal("b"),
[]
)
]
)
]
)

self.assertFalse(constraint.check(counter_example))
example = DerivationTree(
NonTerminal("<start>"),
[
DerivationTree(
NonTerminal("<ab>"),
[
DerivationTree(
Terminal("a"),
[]
)
]
)
]
)
self.assertTrue(constraint.check(example))

def test_indirect_children(self):
file = open("tests/resources/indirect_children.fan", "r")
grammar, constraint = parse(file, use_stdlib=False)

self.assertEqual(1, len(constraint))
constraint = constraint[0]

counter_example = grammar.parse("19")
self.assertFalse(constraint.check(counter_example))

example = grammar.parse("11")
self.assertTrue(constraint.check(example))

def test_accessing_children(self):
file = open("tests/resources/children.fan", "r")
grammar, constraint = parse(file, use_stdlib=False)
constraint = constraint[0]

counter_example = grammar.parse("11")
self.assertFalse(constraint.check(counter_example))

example = grammar.parse("01")
self.assertTrue(constraint.check(example))

def test_complex_constraint(self):
constraint = """
int(<number>) % 2 == 0;
37 changes: 37 additions & 0 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from fandango.language.grammar import Disambiguator, Node, NonTerminalNode, Grammar
from fandango.language.parse import parse
from fandango.language.tree import DerivationTree
from fandango.evolution.algorithm import Fandango


class ConstraintTest(unittest.TestCase):
@@ -37,3 +38,39 @@ def test_parse(self):
for path in GRAMMAR.traverse_derivation(tree):
print(path)

def get_solutions(self, grammar, constraints):
fandango = Fandango(grammar=grammar, constraints=constraints, desired_solutions=10)
return fandango.evolve()

def test_generators(self):
file = open("tests/resources/bar.fan", "r")
GRAMMAR, constraints = parse(file, use_stdlib=False)
expected = ["bar" for _ in range(10)]
actual = self.get_solutions(GRAMMAR, constraints)

self.assertEqual(expected, actual)

def test_repetitions(self):
file = open("tests/resources/repetitions.fan", "r")
GRAMMAR, c = parse(file, use_stdlib=False)
expected = ["aaa" for _ in range(10)]
actual = self.get_solutions(GRAMMAR, c)

self.assertEqual(expected, actual)

def test_repetitions_slice(self):
file = open("tests/resources/slicing.fan", "r")
GRAMMAR, c = parse(file, use_stdlib=False)
solutions = self.get_solutions(GRAMMAR, c)
for solution in solutions:
self.assertGreaterEqual(len(str(solution)), 3)
self.assertLessEqual(len(str(solution)), 10)

def test_repetition_min(self):
file = open("tests/resources/min_reps.fan", "r")
GRAMMAR, c = parse(file, use_stdlib=False)
solutions = self.get_solutions(GRAMMAR, c)
for solution in solutions:
self.assertGreaterEqual(len(str(solution)), 3)