Skip to content

Commit f6ec53d

Browse files
authored
Merge pull request #41 from Brainrotlang/feat/add-test-rule-to-makefile
add test rule to makefile, add contributing doc and pull request template
2 parents bf4df3c + 4ae521e commit f6ec53d

File tree

4 files changed

+181
-5
lines changed

4 files changed

+181
-5
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Description
2+
3+
<!-- Briefly describe your changes, including any relevant motivation or context. -->
4+
5+
## Related Issue
6+
7+
<!-- If this PR fixes an issue, include "Fixes #<issue_number>". -->
8+
9+
Fixes #<issue_number>
10+
11+
## Type of Change
12+
13+
- [ ] Bug fix (non-breaking change which fixes an issue)
14+
- [ ] New feature (non-breaking change which adds functionality)
15+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
16+
- [ ] Documentation update
17+
- [ ] Performance improvement
18+
19+
## Checklist
20+
21+
- [ ] My code follows the style guidelines of this project
22+
- [ ] I have performed a self-review of my own code
23+
- [ ] I have documented my changes in the code or documentation
24+
- [ ] I have added tests that prove my changes work (if applicable)
25+
- [ ] All new and existing tests pass

CONTRIBUTING.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Contributing to Brainrot
2+
3+
Welcome to Brainrot! We're excited that you want to contribute. This document provides guidelines and information for contributing to the project.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you are expected to uphold our Code of Conduct (follows standard open source practices).
8+
9+
## Getting Started
10+
11+
1. Fork the repository
12+
2. Clone your fork: `git clone https://github.com/yourusername/Brainrot.git`
13+
3. Create a branch for your changes: `git checkout -b feature/your-feature-name`
14+
15+
## Development Environment
16+
17+
### Prerequisites
18+
19+
- C compiler (gcc recommended)
20+
- Flex and Bison
21+
- Make
22+
23+
### Building the Project
24+
25+
```bash
26+
make clean
27+
make
28+
```
29+
30+
### Running Tests
31+
32+
The test suite can be run using:
33+
34+
```bash
35+
make test
36+
```
37+
38+
## Project Structure
39+
40+
- `ast.h` / `ast.c`: Abstract Syntax Tree implementation
41+
- `lang.y`: Bison grammar file
42+
- `lang.l`: Flex lexer file
43+
- `examples/`: Example Brainrot programs
44+
- `tests/`: Test suite
45+
46+
## Adding New Features
47+
48+
1. First, check existing issues and PRs to avoid duplicate work
49+
2. Create an issue discussing the feature before implementing
50+
3. Follow the existing code style
51+
4. Add appropriate tests in `tests/`
52+
5. Add example usage in `examples/`
53+
54+
## Testing Guidelines
55+
56+
1. All new features must include tests
57+
2. Test files go in `tests/`
58+
3. Expected outputs should be added to `expected_results.json`
59+
4. Tests should cover:
60+
- Happy path
61+
- Error conditions
62+
- Edge cases
63+
64+
## Pull Request Process
65+
66+
1. Update documentation as needed
67+
2. Add or update tests
68+
3. Ensure all tests pass
69+
4. Update CHANGELOG.md if applicable
70+
5. Reference any related issues
71+
72+
Example PR format:
73+
74+
```markdown
75+
## Description
76+
77+
Brief description of changes
78+
79+
## Related Issue
80+
81+
Fixes #<issue_number>
82+
83+
## Type of Change
84+
85+
- [ ] Bug fix
86+
- [ ] New feature
87+
- [ ] Documentation update
88+
- [ ] Performance improvement
89+
```
90+
91+
## Style Guide
92+
93+
### C Code Style
94+
95+
- Use 4 spaces for indentation
96+
- Maximum line length of 80 characters
97+
- Function names use snake_case
98+
- Constants use UPPER_SNAKE_CASE
99+
- Add comments for complex logic
100+
- Include parameter documentation for functions
101+
102+
### Grammar Style
103+
104+
- Token names should be descriptive
105+
- Use consistent naming patterns for similar concepts
106+
- Document grammar rules with examples
107+
108+
## Documentation
109+
110+
- Keep README.md updated with new features
111+
- Document all public functions
112+
- Include examples for new features
113+
- Use clear, concise language
114+
115+
## Bug Reports
116+
117+
When filing a bug report, include:
118+
119+
1. Brainrot version
120+
2. Operating system
121+
3. Complete error message
122+
4. Minimal reproduction code
123+
5. Expected vs actual behavior
124+
125+
## Getting Help
126+
127+
If you need help, you can:
128+
129+
1. Check existing issues
130+
2. Create a new issue with your question
131+
3. Add [HELP WANTED] tag for implementation assistance
132+
133+
## License
134+
135+
By contributing, you agree that your contributions will be licensed under the same terms as the main project.
136+
137+
## Acknowledgments
138+
139+
Thank you to all contributors who help make Brainrot better!

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ all:
33
flex lang.l
44
gcc -o brainrot lang.tab.c lex.yy.c ast.c -lfl
55

6+
test:
7+
pytest -v
8+
69
clean:
710
rm -rf lang.lex.c lang.tab.c lang.tab.h lex.yy.c brainrot

tests/test_brainrot.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
import os
44
import pytest
55

6-
# Load expected results from JSON file
7-
with open("expected_results.json", "r") as file:
6+
# Get the absolute path to the directory containing the script
7+
script_dir = os.path.dirname(__file__)
8+
9+
# Construct the full path to the JSON file with expected results
10+
file_path = os.path.join(script_dir, "expected_results.json")
11+
12+
# Load expected results from the JSON file
13+
with open(file_path, "r") as file:
814
expected_results = json.load(file)
915

1016
@pytest.mark.parametrize("example,expected_output", expected_results.items())
1117
def test_brainrot_examples(example, expected_output):
18+
# Construct absolute paths for the brainrot executable and example file
19+
brainrot_path = os.path.abspath(os.path.join(script_dir, "../brainrot"))
20+
example_file_path = os.path.abspath(os.path.join(script_dir, f"../examples/{example}"))
21+
1222
# Define the command to execute
13-
command = f".././brainrot < ../examples/{example}"
23+
command = f"{brainrot_path} < {example_file_path}"
1424

1525
# Run the command and capture the output
1626
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
@@ -32,6 +42,5 @@ def test_brainrot_examples(example, expected_output):
3242
f"Stderr:\n{result.stderr}"
3343
)
3444

35-
3645
if __name__ == "__main__":
37-
pytest.main(["-v", os.path.basename(__file__)])
46+
pytest.main(["-v", os.path.abspath(__file__)])

0 commit comments

Comments
 (0)