Skip to content

Commit

Permalink
Escape all literal dollar signs (#3)
Browse files Browse the repository at this point in the history
* Escape all literal dollar signs

Signed-off-by: Bolun Thompson <bolunthompson@ucla.edu>

* add libdash tests to shasta

* fix: don't escape singular $ signs

* Add github action to run tests

* Refactor: download libdash only for tests

* fix workflow

* add clean libdash_tests

* refactor test action

* fix os

* remove submodule

* fix gh action typo

* add: install deps in test runner makefile

* Move setup test outside of Makefile

Prevents calling test setup every time the tests are run.

---------

Signed-off-by: Bolun Thompson <bolunthompson@ucla.edu>
  • Loading branch information
BolunThompson authored Dec 2, 2024
1 parent 838e706 commit a85f998
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened, ready_for_review]
paths:
- shasta/**
push:
branches:
- main
- future
paths:
- libdash/**
- shasta/**
jobs:
Shasta-Test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Running Tests
run: |
cd tests;
./setup_test.sh
make test
test_succ=$?
timer="$(LANG=en_us_88591; date)"
echo "VERSION<<EOF" >> "$GITHUB_ENV"
echo "OS:${{matrix.os}}" >> "$GITHUB_ENV"
echo "$timer" >> "$GITHUB_ENV"
cat python.log >> "$GITHUB_ENV"
echo 'EOF' >> "$GITHUB_ENV"
exit $test_succ
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*__pycache__*
dist/*
shasta.egg-info/*
tests/libdash_tests/
tests/*.log
3 changes: 2 additions & 1 deletion shasta/ast_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ def string_of_arg(args, quote_mode=UNQUOTED):
text = []
while i < len(args):
c = args[i].pretty(quote_mode=quote_mode)
if c == "$" and (i+1 < len(args)) and isinstance(args[i+1],EArgChar):
# escape dollar signs to avoid variable interpolation
if c == "$" and i + 1 < len(args):
c = "\\$"
text.append(c)

Expand Down
21 changes: 21 additions & 0 deletions tests/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Michael Greenberg, Konstantinos Kallas, Thurston Dang, and Bolun Thompson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: setup_test test clean

test: rt.py ../shasta/*.py
@find libdash_tests/tests libdash_tests/pash_tests -type f | while read f; do libdash_tests/round_trip.sh ./rt.py "$$f"; done | tee python.log
@cat python.log | egrep '^[A-Z0-9_]+:' | cut -d ':' -f 1 | sort | uniq -c
@grep ':' python.log && echo "FAILED" && exit 1 || exit 0

clean:
rm -rf $(wildcard *.log) libdash_tests
20 changes: 20 additions & 0 deletions tests/rt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

import sys

import libdash
from shasta.json_to_ast import to_ast_node


sys.setrecursionlimit (9001)

def print_asts(new_asts):
for (ast, lines, linno_before, linno_after) in new_asts:
print(to_ast_node(ast).pretty())

if (len(sys.argv) == 1):
new_asts = libdash.parse("-", True)
else:
new_asts = libdash.parse(sys.argv[1], True)

print_asts(new_asts)
9 changes: 9 additions & 0 deletions tests/setup_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ ! -d libdash_tests/ ]; then
git clone https://github.com/binpash/libdash.git
mv libdash/test libdash_tests
rm -rf libdash
fi

pip install .. libdash

0 comments on commit a85f998

Please sign in to comment.