This commit is contained in:
2026-06-11 18:53:08 -07:00
parent 3f73cd4d85
commit e91dbc07ba
4 changed files with 79 additions and 10 deletions
+60 -2
View File
@@ -13,6 +13,7 @@
% gso_tokens/1 % gso_tokens/1
%]). %]).
-export([start/1]). -export([start/1]).
-export([do_help/0]).
-include("$gsc_include/gsc.hrl"). -include("$gsc_include/gsc.hrl").
-include("ansi.hrl"). -include("ansi.hrl").
@@ -21,7 +22,64 @@ do_help() ->
io:format("~ts", [help_screen()]). io:format("~ts", [help_screen()]).
help_screen() -> help_screen() ->
["you can't help people who refuse to help themsleves\n"]. ["Usage: gsc <command> [args]\n"
"\n"
"COMMANDS\n"
"\n"
" (no args)\n"
" shell\n"
" eshell\n"
" Start an Erlang shell with GSC loaded.\n"
"\n"
" tokens <file>\n"
" Print GSC tokens from <file>, one per line.\n"
"\n"
" tokens -c <file>\n"
" tokens --color <file>\n"
" tcat <file>\n"
" ctokens <file>\n"
" color_tokens <file>\n"
" Print <file> to stdout with each token highlighted in a\n"
" different color so token boundaries are visible.\n"
"\n"
" gso tokens <file>\n"
" gso_tokens <file>\n"
" Print sophia-compatible (so_scan) tokens from <file>,\n"
" one per line.\n"
"\n"
" rmm <file>\n"
" Compile <file> and call its main/0 with GSC context loaded.\n"
" Useful for running scratch scripts.\n"
"\n"
"TEST HARNESS (gsc test ...)\n"
"\n"
" gsc test -l\n"
" gsc test --list\n"
" List available named tests.\n"
"\n"
" gsc test -a\n"
" gsc test --all\n"
" Run all named tests.\n"
"\n"
" gsc test so tokens <file>\n"
" gsc test so_tokens <file>\n"
" Print sophia-original (so_scan) tokens from <file>,\n"
" one per line.\n"
"\n"
" gsc test tokenizers_agree <file>\n"
" Check whether gsc and so_scan produce identical tokens\n"
" for <file>. Prints 'true' or 'false'.\n"
" <file> is resolved relative to cwd.\n"
" Example:\n"
" gsc test tokenizers_agree foo.aes\n"
"\n"
" gsc test <name>\n"
" Run a named test module. 'gsc test foo' and\n"
" 'gsc test gsc_test_foo' are equivalent.\n"
" Use 'gsc test --list' to see available names.\n"
"\n"
].
-spec start(ArgV) -> ok -spec start(ArgV) -> ok
when ArgV :: [string()]. when ArgV :: [string()].
@@ -42,7 +100,7 @@ start(ArgV) ->
do(["test" | Tests]) -> do(["test" | Tests]) ->
do_test(Tests); do_test(Tests);
% slowly phasing out shitty names like lctokens % slowly phasing out shitty names like lctokens
% tokens = native sfc token representation % tokens = native gsc token representation
do(["tokens", Foo]) -> do_tokens(Foo); do(["tokens", Foo]) -> do_tokens(Foo);
% print source file to screen with token boundaries % print source file to screen with token boundaries
% highlighted % highlighted
+2 -2
View File
@@ -121,8 +121,8 @@ concat_property(FileName, FilePath) ->
{FileName ++ ": file = sum(tokens)", {FileName ++ ": file = sum(tokens)",
fun() -> fun() ->
case gsc:tokens_from_file(FileChars) of case gsc:tokens_from_file(FileChars) of
{ok, SfcTokens} -> {ok, GscTokens} ->
ConcatStr = concat_token_strs(SfcTokens, []), ConcatStr = concat_token_strs(GscTokens, []),
?assertEqual(FileChars, ConcatStr); ?assertEqual(FileChars, ConcatStr);
_Error -> _Error ->
ok ok
+9 -6
View File
@@ -24,8 +24,8 @@ cli_args(TestNames) ->
ts_utils:tidily(fun() -> do_gsc_test(TestNames) end). ts_utils:tidily(fun() -> do_gsc_test(TestNames) end).
do_gsc_test(["-h" | _]) -> do_help(); %do_gsc_test(["-h" | _]) -> do_help();
do_gsc_test(["--help" | _]) -> do_help(); %do_gsc_test(["--help" | _]) -> do_help();
do_gsc_test(["-l" | _]) -> do_list(); do_gsc_test(["-l" | _]) -> do_list();
do_gsc_test(["--list" | _]) -> do_list(); do_gsc_test(["--list" | _]) -> do_list();
do_gsc_test(["-a" | _]) -> do_all(); do_gsc_test(["-a" | _]) -> do_all();
@@ -35,14 +35,17 @@ do_gsc_test(["so", "tokens", X]) -> do_so_tokens(X);
do_gsc_test(["tokenizers_agree", X]) -> do_gsc_test(["tokenizers_agree", X]) ->
do_tokenizers_agree(X); do_tokenizers_agree(X);
do_gsc_test([TestName]) -> do_gsc_test([TestName]) ->
ts_utils:run_test_by_name(TestName); case ts_utils:test_exists_by_name(TestName) of
true -> ts_utils:run_test_by_name(TestName);
false -> gsc_cli:do_help()
end;
do_gsc_test(_) -> do_gsc_test(_) ->
do_help(). gsc_cli:do_help().
do_help() -> %do_help() ->
io:format("go help yourself~n"). % io:format("go help yourself~n").
do_list() -> do_list() ->
Names = ts_utils:runnable_test_names(), Names = ts_utils:runnable_test_names(),
+8
View File
@@ -10,6 +10,7 @@
load_dep/1, load_dep/1,
clean_after/1, tidily/1, clean_after/1, tidily/1,
delete_beams/0, tidy/0, delete_beams/0, tidy/0,
test_exists_by_name/1,
run_test_by_name/1, run_test_by_name/1,
rmm/1, run_mod_main/1, rmm/1, run_mod_main/1,
runnable_test_names/0, runnable_test_names/0,
@@ -110,6 +111,13 @@ tidy() ->
delete_beams(). delete_beams().
test_exists_by_name(Name) when is_list(Name) ->
case find_test_by_name(Name) of
{good, _} -> true;
{bad, _} -> true;
not_found -> false
end.
-spec run_test_by_name(Name) -> Result when -spec run_test_by_name(Name) -> Result when
Name :: string(), Name :: string(),
Result :: ok. Result :: ok.