From 156c591e9e20eb0964ee9f6ac60b0afb2053a3d5 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Sat, 11 Jun 2022 14:28:20 -0400 Subject: [PATCH 01/11] Script to redeploy testlib.sml to all exercises on changes. The directory name `sml-bin` makes the most sense to me for these sml "scripts". Adding them to the makefile also makes it even easier to use these than it is when using "#! /usr/bin/env -S poly --script" as a shebang line. Consequently this should be portable to any Windows system that has GNU make installed, so it is probably better than the shebang. In the code I used the path library to help make things OS portable, but I haven't ever used SML on Windows, so it is untested for that enironment. --- Makefile | 3 +++ sml-bin/redeploy-testlib.sml | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 sml-bin/redeploy-testlib.sml diff --git a/Makefile b/Makefile index a658f08..74ab858 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,7 @@ test-%: @cd ./exercises/practice/$(exercise) && cat test.sml | sed 's/$(exercise).sml/.meta\/example.sml/' | poly -q @echo +redeploy-testlib: + poly --script sml-bin/redeploy-testlib.sml + .PHONY: test diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml new file mode 100755 index 0000000..c7ded11 --- /dev/null +++ b/sml-bin/redeploy-testlib.sml @@ -0,0 +1,45 @@ +open OS.Path; +open OS.FileSys; + +fun printLn x = print (x ^ "\n") + +fun fileExists x = access (x,[]) + +fun testLibName base slug = + joinDirFile + { + dir = (concat (base,slug)) + , file = "testlib.sml" + } + +fun dirList dirname = let + fun go d xs = + case readDir d of + SOME x => go d (x::xs) + | NONE => (closeDir d; xs); +in + go (openDir dirname) [] +end + +fun fileBytes path = let + val in' = BinIO.openIn path; + val bytes = BinIO.inputAll in'; +in + BinIO.closeIn in'; bytes +end + +fun writeFileBytes bytes path = let + val out = BinIO.openOut path; +in + BinIO.output (out, bytes); + BinIO.closeOut out +end + +val _ = let + val concept = concat ((getDir ()), (fromUnixPath "exercise/concept")); + val practice = concat ((getDir ()), (fromUnixPath "exercises/practice")); + + val testLib = fileBytes "lib/testlib.sml"; +in + app (writeFileBytes testLib o testLibName practice) (dirList practice) +end From 627c2dc5a392c3ab681484ffb0c0ad57c8017de0 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Sun, 12 Jun 2022 17:16:02 -0400 Subject: [PATCH 02/11] Change file perms to 664 for sml-bin/redeploy-testlib.sml I had set it to 775 when it had a shebang and lived in `bin`. Trying to execute it will fail, so it shouldn't be executable. --- sml-bin/redeploy-testlib.sml | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 sml-bin/redeploy-testlib.sml diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml old mode 100755 new mode 100644 From 110d8d7452d06b09f544b294aa8625dc223792ac Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Sun, 12 Jun 2022 17:24:41 -0400 Subject: [PATCH 03/11] Make redeploy-testlib phone as well. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 74ab858..75298c4 100644 --- a/Makefile +++ b/Makefile @@ -18,4 +18,4 @@ test-%: redeploy-testlib: poly --script sml-bin/redeploy-testlib.sml -.PHONY: test +.PHONY: test redeploy-testlib From 721dd7bdc914367aa9a4319da9641c2f8b2d924c Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Sun, 12 Jun 2022 17:37:00 -0400 Subject: [PATCH 04/11] Use qualified names. I shouldn't have combined to actions but I did. I removed all unnecessary semicolons while refactoring to use qualified names. Sorry. --- sml-bin/redeploy-testlib.sml | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml index c7ded11..ebb478e 100644 --- a/sml-bin/redeploy-testlib.sml +++ b/sml-bin/redeploy-testlib.sml @@ -1,45 +1,46 @@ -open OS.Path; -open OS.FileSys; +structure Path = OS.Path; +structure File = OS.FileSys; fun printLn x = print (x ^ "\n") -fun fileExists x = access (x,[]) +fun fileExists x = File.access (x,[]) fun testLibName base slug = - joinDirFile + Path.joinDirFile { - dir = (concat (base,slug)) + dir = (Path.concat (base,slug)) , file = "testlib.sml" } fun dirList dirname = let fun go d xs = - case readDir d of + case File.readDir d of SOME x => go d (x::xs) - | NONE => (closeDir d; xs); + | NONE => (File.closeDir d; xs) in - go (openDir dirname) [] + go (File.openDir dirname) [] end fun fileBytes path = let - val in' = BinIO.openIn path; - val bytes = BinIO.inputAll in'; + val in' = BinIO.openIn path + val bytes = BinIO.inputAll in' in BinIO.closeIn in'; bytes end fun writeFileBytes bytes path = let - val out = BinIO.openOut path; + val out = BinIO.openOut path in BinIO.output (out, bytes); BinIO.closeOut out end -val _ = let - val concept = concat ((getDir ()), (fromUnixPath "exercise/concept")); - val practice = concat ((getDir ()), (fromUnixPath "exercises/practice")); +fun relUnixPathToAbs x= Path.concat ((File.getDir ()), Path.fromUnixPath x) - val testLib = fileBytes "lib/testlib.sml"; +val _ = let + val concept = relUnixPathToAbs "exercise/concept" + val practice = relUnixPathToAbs"exercises/practice" + val testLib = fileBytes "lib/testlib.sml" in app (writeFileBytes testLib o testLibName practice) (dirList practice) end From 32774e51464759d15131e1a4ac08bbe11e5f37fd Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Sun, 12 Jun 2022 18:08:06 -0400 Subject: [PATCH 05/11] Format redeploy-testlib.sml like teslib.sml I also found and removed two more unnecessary semicolons. --- sml-bin/redeploy-testlib.sml | 50 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml index ebb478e..cd4d94f 100644 --- a/sml-bin/redeploy-testlib.sml +++ b/sml-bin/redeploy-testlib.sml @@ -1,46 +1,50 @@ -structure Path = OS.Path; -structure File = OS.FileSys; +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 + 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 + case File.readDir d of + SOME x => go d (x::xs) + | NONE => (File.closeDir d; xs) + in go (File.openDir dirname) [] -end + end -fun fileBytes path = let +fun fileBytes path = + let val in' = BinIO.openIn path val bytes = BinIO.inputAll in' -in + in BinIO.closeIn in'; bytes -end + end -fun writeFileBytes bytes path = let +fun writeFileBytes bytes path = + let val out = BinIO.openOut path -in + in BinIO.output (out, bytes); BinIO.closeOut out -end + end fun relUnixPathToAbs x= Path.concat ((File.getDir ()), Path.fromUnixPath x) -val _ = let +val _ = + let val concept = relUnixPathToAbs "exercise/concept" val practice = relUnixPathToAbs"exercises/practice" val testLib = fileBytes "lib/testlib.sml" -in + in app (writeFileBytes testLib o testLibName practice) (dirList practice) -end + end From f276a743b5ae4849d16a3326a5bd2cc285179cb5 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Tue, 14 Jun 2022 16:31:49 -0400 Subject: [PATCH 06/11] Include testlib sync policy in the README. I wrote a brief note about keeping testlib.sml in sync for all exercises in the track, and I mentioned 'make redeploy-testlib' as the provided tool for handling this requirement. I did not elaborate on a policy, because we still don't really have one. Further work related to #110 should result in a clear policy, and at that point the README.md might need some more updating. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b93565b..b89b836 100644 --- a/README.md +++ b/README.md @@ -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` +when it is updated. + +This helper has these structures: ```sml structure Expect: From d4c26df624c0ff61f75530c273ad1b6270177e57 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Tue, 14 Jun 2022 16:38:09 -0400 Subject: [PATCH 07/11] Formatting, names, parentheses. --- sml-bin/redeploy-testlib.sml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml index cd4d94f..04ebf46 100644 --- a/sml-bin/redeploy-testlib.sml +++ b/sml-bin/redeploy-testlib.sml @@ -8,7 +8,7 @@ fun fileExists x = File.access (x,[]) fun testLibName base slug = Path.joinDirFile { - dir = (Path.concat (base,slug)), + dir = Path.concat (base,slug), file = "testlib.sml" } @@ -24,27 +24,26 @@ fun dirList dirname = fun fileBytes path = let - val in' = BinIO.openIn path - val bytes = BinIO.inputAll in' + val instream = BinIO.openIn path + val bytes = BinIO.inputAll instream in - BinIO.closeIn in'; bytes + BinIO.closeIn instream; bytes end fun writeFileBytes bytes path = let val out = BinIO.openOut path in - BinIO.output (out, bytes); + BinIO.output (out,bytes); BinIO.closeOut out end -fun relUnixPathToAbs x= Path.concat ((File.getDir ()), Path.fromUnixPath x) +fun relUnixPathToAbs x = Path.concat (File.getDir (), Path.fromUnixPath x) val _ = let - val concept = relUnixPathToAbs "exercise/concept" - val practice = relUnixPathToAbs"exercises/practice" + val practice = relUnixPathToAbs "exercises/practice" val testLib = fileBytes "lib/testlib.sml" in - app (writeFileBytes testLib o testLibName practice) (dirList practice) + List.app (writeFileBytes testLib o testLibName practice) (dirList practice) end From 48de3e8277560075e215b5703842d65442d604e6 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Thu, 16 Jun 2022 09:13:07 -0400 Subject: [PATCH 08/11] Update README.md Co-authored-by: Victor Goff --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b89b836..c083c82 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Every exercise must have at least these files: ### `testlib.sml` 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` +`make redeploy-testlib` is provided for synchronizing all exercises with `lib/testlib.sml` when it is updated. This helper has these structures: From f75f6587b7a9352da1b1b6734cfc3c58bf5474ca Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Thu, 16 Jun 2022 09:14:38 -0400 Subject: [PATCH 09/11] Add spaces inside tuples. --- sml-bin/redeploy-testlib.sml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sml-bin/redeploy-testlib.sml b/sml-bin/redeploy-testlib.sml index 04ebf46..b5fd88c 100644 --- a/sml-bin/redeploy-testlib.sml +++ b/sml-bin/redeploy-testlib.sml @@ -3,12 +3,12 @@ structure File = OS.FileSys fun printLn x = print (x ^ "\n") -fun fileExists x = File.access (x,[]) +fun fileExists x = File.access (x, []) fun testLibName base slug = Path.joinDirFile { - dir = Path.concat (base,slug), + dir = Path.concat (base, slug), file = "testlib.sml" } @@ -34,7 +34,7 @@ fun writeFileBytes bytes path = let val out = BinIO.openOut path in - BinIO.output (out,bytes); + BinIO.output (out, bytes); BinIO.closeOut out end From 57b38853e5fafcc09e0d305a45648ee045f833fa Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Mon, 20 Jun 2022 09:50:18 -0400 Subject: [PATCH 10/11] Use scripts directory instead of sml-bin. --- Makefile | 2 +- {sml-bin => scripts}/redeploy-testlib.sml | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {sml-bin => scripts}/redeploy-testlib.sml (100%) diff --git a/Makefile b/Makefile index 75298c4..a00f97c 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,6 @@ test-%: @echo redeploy-testlib: - poly --script sml-bin/redeploy-testlib.sml + poly --script scripts/redeploy-testlib.sml .PHONY: test redeploy-testlib diff --git a/sml-bin/redeploy-testlib.sml b/scripts/redeploy-testlib.sml similarity index 100% rename from sml-bin/redeploy-testlib.sml rename to scripts/redeploy-testlib.sml From 38dff0e0b5248ecddf41668112cae7d488b0a344 Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Mon, 20 Jun 2022 09:50:38 -0400 Subject: [PATCH 11/11] Add a documenting comment to redeploy-testlib.sml. Initially, I thought it must be clear enough from the title/name of the script itself, but on further reflection, a documenting comment might help a non-native english speaker avoid the difficulties of ambiguity. --- scripts/redeploy-testlib.sml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/redeploy-testlib.sml b/scripts/redeploy-testlib.sml index b5fd88c..b4cefc5 100644 --- a/scripts/redeploy-testlib.sml +++ b/scripts/redeploy-testlib.sml @@ -1,3 +1,9 @@ +(* Re-deploy lib/testlib.sml on changes. + * + * When lib.testlib.sml is changed it should be updated for all exercises. + * Use this "script" a la `make redeploy-testlib`. + *) + structure Path = OS.Path structure File = OS.FileSys