about summary refs log tree commit diff stats
path: root/cpp/001test
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-22 12:17:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-22 12:17:16 -0700
commitdf0b469f26025ec7f7f7cc88439a8b68c396b97c (patch)
tree09161cf405ad5daa5c27865b861413f09b7baced /cpp/001test
parentd16dee594404a49f68df93f92efa1790e7a17273 (diff)
downloadmu-df0b469f26025ec7f7f7cc88439a8b68c396b97c.tar.gz
1128
Reorganized commandline handling to perform test space assertion in just
one place at the right layer. Hopefully this issue will not bite us
again.
Diffstat (limited to 'cpp/001test')
-rw-r--r--cpp/001test56
1 files changed, 36 insertions, 20 deletions
diff --git a/cpp/001test b/cpp/001test
index 2319348b..38e5a2b6 100644
--- a/cpp/001test
+++ b/cpp/001test
@@ -38,30 +38,40 @@ long Num_failures = 0;
   }
 
 :(before "End Main")
-if (argc == 2 && is_equal(argv[1], "test")) {
-  run_tests();
-  cerr << '\n';
-  if (Num_failures > 0)
-    cerr << Num_failures << " failure"
-         << (Num_failures > 1 ? "s" : "")
-         << '\n';
+if (argc <= 1 || is_equal(argv[1], "--help")) {
+  // need some way to distribute this across layers
+  cerr << "To load files and run 'main': mu file1.mu file2.mu ...\n"
+       << "To run all core tests: mu test\n"
+       << "To load files and run tests defined in them: mu test file1.mu file2.mu ...\n"
+       << "To run just some C++ tests in `test_list` file: mu test n1 n2 ...\n"
+       << "  (look up n1 n2 ... by running `grep -n` on test_list`)\n"
+       ;
   return 0;
 }
-// pass in a set of line numbers in test_file to run just those tests
-if (argc > 2 && is_equal(argv[1], "test") && is_number(argv[2])) {
-  assert(Next_recipe_number < 1000);  // see vm layer
-  for (int i = 2; i < argc; ++i) {
-    run_test(to_int(argv[i])-1);
+if (argc > 1 && is_equal(argv[1], "test")) {
+  // End Test Run Initialization
+  if (argc == 2) {
+    run_tests();
+    cerr << '\n';
+    if (Num_failures > 0)
+      cerr << Num_failures << " failure"
+           << (Num_failures > 1 ? "s" : "")
+           << '\n';
+    return 0;
+  }
+  if (is_number(argv[2])) {
+    // all args are line numbers in test_file specifying tests to run
+    run_tests(argc, argv);
+    cerr << '\n';
+    if (Num_failures > 0)
+      cerr << Num_failures << " failure"
+           << (Num_failures > 1 ? "s" : "")
+           << '\n';
+    return 0;
   }
-  cerr << '\n';
-  if (Num_failures > 0)
-    cerr << Num_failures << " failure"
-         << (Num_failures > 1 ? "s" : "")
-         << '\n';
-  return 0;
-}
 
-// End Test Runs
+  // End Test Runs
+}
 
 :(code)
 void run_tests() {
@@ -73,6 +83,12 @@ void run_tests() {
   // End Tests
 }
 
+void run_tests(int argc, char* argv[]) {
+  for (int i = 2; i < argc; ++i) {
+    run_test(to_int(argv[i])-1);
+  }
+}
+
 void run_test(size_t i) {
   if (i >= sizeof(Tests)/sizeof(Tests[0])) {
     cerr << "no test " << i << '\n';