diff --git a/src/gsc_cli.erl b/src/gsc_cli.erl index 41f06dd..7174f9e 100644 --- a/src/gsc_cli.erl +++ b/src/gsc_cli.erl @@ -13,6 +13,7 @@ % gso_tokens/1 %]). -export([start/1]). +-export([do_help/0]). -include("$gsc_include/gsc.hrl"). -include("ansi.hrl"). @@ -21,7 +22,64 @@ do_help() -> io:format("~ts", [help_screen()]). help_screen() -> - ["you can't help people who refuse to help themsleves\n"]. + ["Usage: gsc [args]\n" + "\n" + "COMMANDS\n" + "\n" + " (no args)\n" + " shell\n" + " eshell\n" + " Start an Erlang shell with GSC loaded.\n" + "\n" + " tokens \n" + " Print GSC tokens from , one per line.\n" + "\n" + " tokens -c \n" + " tokens --color \n" + " tcat \n" + " ctokens \n" + " color_tokens \n" + " Print to stdout with each token highlighted in a\n" + " different color so token boundaries are visible.\n" + "\n" + " gso tokens \n" + " gso_tokens \n" + " Print sophia-compatible (so_scan) tokens from ,\n" + " one per line.\n" + "\n" + " rmm \n" + " Compile 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 \n" + " gsc test so_tokens \n" + " Print sophia-original (so_scan) tokens from ,\n" + " one per line.\n" + "\n" + " gsc test tokenizers_agree \n" + " Check whether gsc and so_scan produce identical tokens\n" + " for . Prints 'true' or 'false'.\n" + " is resolved relative to cwd.\n" + " Example:\n" + " gsc test tokenizers_agree foo.aes\n" + "\n" + " gsc test \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 when ArgV :: [string()]. @@ -42,7 +100,7 @@ start(ArgV) -> do(["test" | Tests]) -> do_test(Tests); % slowly phasing out shitty names like lctokens -% tokens = native sfc token representation +% tokens = native gsc token representation do(["tokens", Foo]) -> do_tokens(Foo); % print source file to screen with token boundaries % highlighted diff --git a/test/gsc_test_tokens.erl b/test/gsc_test_tokens.erl index 017e56b..67389a2 100644 --- a/test/gsc_test_tokens.erl +++ b/test/gsc_test_tokens.erl @@ -121,8 +121,8 @@ concat_property(FileName, FilePath) -> {FileName ++ ": file = sum(tokens)", fun() -> case gsc:tokens_from_file(FileChars) of - {ok, SfcTokens} -> - ConcatStr = concat_token_strs(SfcTokens, []), + {ok, GscTokens} -> + ConcatStr = concat_token_strs(GscTokens, []), ?assertEqual(FileChars, ConcatStr); _Error -> ok diff --git a/test/gsc_tests.erl b/test/gsc_tests.erl index 62afad3..4ccfa3d 100644 --- a/test/gsc_tests.erl +++ b/test/gsc_tests.erl @@ -24,8 +24,8 @@ cli_args(TestNames) -> ts_utils:tidily(fun() -> do_gsc_test(TestNames) end). -do_gsc_test(["-h" | _]) -> do_help(); -do_gsc_test(["--help" | _]) -> do_help(); +%do_gsc_test(["-h" | _]) -> do_help(); +%do_gsc_test(["--help" | _]) -> do_help(); do_gsc_test(["-l" | _]) -> do_list(); do_gsc_test(["--list" | _]) -> do_list(); 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_tokenizers_agree(X); 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_help(). + gsc_cli:do_help(). -do_help() -> - io:format("go help yourself~n"). +%do_help() -> +% io:format("go help yourself~n"). do_list() -> Names = ts_utils:runnable_test_names(), diff --git a/test/ts_utils.erl b/test/ts_utils.erl index 539c254..6531a09 100644 --- a/test/ts_utils.erl +++ b/test/ts_utils.erl @@ -10,6 +10,7 @@ load_dep/1, clean_after/1, tidily/1, delete_beams/0, tidy/0, + test_exists_by_name/1, run_test_by_name/1, rmm/1, run_mod_main/1, runnable_test_names/0, @@ -110,6 +111,13 @@ tidy() -> 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 Name :: string(), Result :: ok.