Skip to content

Commit

Permalink
Merge pull request #2 from christian-byrne/grade-scripts
Browse files Browse the repository at this point in the history
Update startup scripts and README
  • Loading branch information
christian-byrne authored Sep 27, 2024
2 parents 39dc92a + 5287e5e commit 223ced8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 14 deletions.
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@


<!-- > [!NOTE]
> [!NOTE]
>
> By default, tests are discovered by looking for sml files that start with `test_` in the `tests` directory. -->
> By default, tests are discovered by looking for sml files that start with `test_` in the `tests` directory.
Setup:
## Setup

```sh
chmod +x ./install
./install
```

Run tests:
## Run tests

```
chmod +x ./test
./test
```

Options
## Options

```sh
usage: test.py [-h] [-x] [--cache-path CACHE_PATH] [--cache-show [CACHE_SHOW]] [--cache-clear] [-k EXPRESSION]
Expand Down Expand Up @@ -68,10 +68,11 @@ options:

```
<!--
## Writing Tests
Source file:
##### Example Source file:
```sml
(* src/program.sml *)
Expand All @@ -80,7 +81,7 @@ fun factorial(0) = 1
| factorial(n) = n * factorial(n - 1);
```
Test file:
##### Example Test file:
```sml
(* tests/test_program_factorial.sml *)
Expand All @@ -97,4 +98,38 @@ val testCasesFactorial = [
];

runTestCasesIntInt(testCasesFactorial);
``` -->
```
## SML Wiki/Reference
Builds local SML wiki site and opens it in the browser.
```sh
chmod +x ./start-wiki
./start-wiki
```
Changes can be made to the wiki by changing files in [wiki/docs](./wiki/docs)
## Lectura Scripts
Set credentials in `.env` file ([`.env.example`](./.env.example))
##### Connect Lectura
```sh
chmod +x ./connect-lectura
./connect-lectura
```
Press `Ctrl+V`
##### Submit Lectura
```sh
chmod +x ./submit-lectura
./submit-lectura <path-to-file>
```
Press `Ctrl+V`
30 changes: 30 additions & 0 deletions start-wiki
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#!/bin/bash

sudo apt update

# Function to install Node.js and npm
install_node_npm() {
echo "Node.js and npm not found. Installing..."
# Add NodeSource repository and install Node.js (this installs npm automatically)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
echo "Node.js and npm installed successfully."
}

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
install_node_npm
else
echo "Node.js is already installed. Version: $(node -v)"
fi

# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo "npm not found, but Node.js is installed. Installing npm..."
sudo apt install -y npm
echo "npm installed successfully."
else
echo "npm is already installed. Version: $(npm -v)"
fi

# Start the wiki server
# https://github.com/smlhelp/book
npm install
npm start

# Open the wiki in the default web browser
xdg-open http://localhost:3000/book/
19 changes: 14 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,23 @@ def clear_cache():
if test == Path(ignore):
logging.info(f"Ignoring test {test} because of ignore {ignore}")
continue

# If --last-failed is set, only include the tests that are in the 'failed_tests' cache
if args.lf and test not in last_failed_tests:
continue

logging.info(f"Found test {test}")

# If --failed-first is set and test was failed previously, prepend it to the test list so it is run first
if args.ff and test in last_failed_tests:
tests.appendleft(test)
tests.appendleft(Path(test))
continue

# If --new-first is set and test is new, prepend it to the test list so it is run first
if args.nf and test not in all_seen_tests:
tests.appendleft(test)
tests.appendleft(Path(test))
continue
logging.info(f"Found test {test}")

tests.append(Path(test))

logging.info(f"Found {len(tests)} tests")
Expand Down Expand Up @@ -282,7 +287,7 @@ def check_for_compile_error(output: str) -> bool:
def run_test(test_path: Path):
global failed_tests
if not isinstance(test_path, Path):
raise ValueError(
raise TypeError(
f"Expected test_path to be of type Path, but got {type(test_path)}"
)

Expand Down Expand Up @@ -348,7 +353,11 @@ def run_test(test_path: Path):
cache = {}

def write_(test_set: Set[Path], cache_key: str):
cache[cache_key] = str(test_set.pop().resolve()) if test_set else ""
if len(test_set) == 0:
cache[cache_key] = []
return

cache[cache_key] = [str(test.resolve()) for test in test_set]

write_(runtime_error_tests, "runtime_error_tests")
write_(failed_tests, "failed_tests")
Expand Down

0 comments on commit 223ced8

Please sign in to comment.