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

Script to redeploy testlib.sml to all exercises on changes. #206

Merged
merged 11 commits into from
Jun 20, 2022
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ test-%:
@cd ./exercises/practice/$(exercise) && cat test.sml | sed 's/$(exercise).sml/.meta\/example.sml/' | poly -q
@echo

.PHONY: test
redeploy-testlib:
poly --script sml-bin/redeploy-testlib.sml

.PHONY: test redeploy-testlib
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Every exercise must have at least these files:

### `testlib.sml`

This helper has this structures:
The copy of `testlib.sml` for each exercise should be in sync with `lib/testlib.sml`.
`make redeploy-testlib` is provided for syncing all exercises with `lib/testlib.sml`
guygastineau marked this conversation as resolved.
Show resolved Hide resolved
when it is updated.

This helper has these structures:

```sml
structure Expect:
Expand Down
49 changes: 49 additions & 0 deletions sml-bin/redeploy-testlib.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
structure Path = OS.Path
structure File = OS.FileSys

fun printLn x = print (x ^ "\n")

fun fileExists x = File.access (x,[])

fun testLibName base slug =
Path.joinDirFile
{
dir = Path.concat (base,slug),
file = "testlib.sml"
}

fun dirList dirname =
let
fun go d xs =
case File.readDir d of
SOME x => go d (x::xs)
| NONE => (File.closeDir d; xs)
in
go (File.openDir dirname) []
end

fun fileBytes path =
let
val instream = BinIO.openIn path
val bytes = BinIO.inputAll instream
in
BinIO.closeIn instream; bytes
end

fun writeFileBytes bytes path =
let
val out = BinIO.openOut path
in
BinIO.output (out,bytes);
BinIO.closeOut out
end

fun relUnixPathToAbs x = Path.concat (File.getDir (), Path.fromUnixPath x)

val _ =
let
val practice = relUnixPathToAbs "exercises/practice"
val testLib = fileBytes "lib/testlib.sml"
in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind writing List.app instead of app? I am usually explicit with these things (because I hate puzzling out what this is if I come back after some time of absence from some particular topic like SML). But it is a question, so feel free to stay with app.

List.app (writeFileBytes testLib o testLibName practice) (dirList practice)
end