Attached is the patch to fix the test suite. That is 01.patch.

> there's a different top-level runner, but it's basically just an old
> version of your tests (as can be seen from my diff --- that's from
> doing a cp of the power*.txt files from your upstream ToT over the
> toybox ones). my question is whether you're happy to dual-license ToT
> or just the exact drops from you?
>
> (i feel like as long as busybox and toybox are modifying the upstream
> _source_ there's value to them running the upstream tests to make sure
> they haven't broken anything.)

I agree. That said, the drops from me are the only parts that are 0BSD
licensed. The reason for this is because my full test suite in my repo
is designed to be run on derivatives of my bc on top of my own bc,
though, I found out that I needed to update it today. I will do so
after work.

Once I update my bc, the following command will be sufficient to run
the entire test suite from my repo on the toybox bc:

$BC_REPO/tests/all.sh 0 0 1 0 $TOYBOX_REPO/toybox bc

where $BC_REPO is the root directory of my bc's repo, and $TOYBOX_REPO
is the same for toybox.

You can also run it on the unstripped toybox:

$BC_REPO/tests/all.sh 0 0 1 0 $TOYBOX_REPO/generated/unstripped/toybox bc

Because that will be available, I don't see a need to doubly license my bc.

Anyway, in making sure my test suite could be run on the bc in toybox,
I found several bugs. The patch to fix them is also attached, as
02.patch.

Gavin Howard
From 5105ae98f013651702d79bae2cfd1d09b1bd3108 Mon Sep 17 00:00:00 2001
From: Gavin Howard <[email protected]>
Date: Fri, 21 Jun 2019 10:18:52 -0600
Subject: [PATCH] bc: remove a power test that is now an error

---
 tests/files/bc/power.txt         | 1 -
 tests/files/bc/power_results.txt | 1 -
 2 files changed, 2 deletions(-)

diff --git a/tests/files/bc/power.txt b/tests/files/bc/power.txt
index 0a61671c..5107be43 100644
--- a/tests/files/bc/power.txt
+++ b/tests/files/bc/power.txt
@@ -40,6 +40,5 @@
 -0.23424398 ^ -81
 -178.234786 ^ -79
 -1274.346 ^ -8
-0 ^ -251
 -0.2959371298 ^ 27
 
diff --git a/tests/files/bc/power_results.txt b/tests/files/bc/power_results.txt
index 6c4f4ec6..1bca1b97 100644
--- a/tests/files/bc/power_results.txt
+++ b/tests/files/bc/power_results.txt
@@ -48,5 +48,4 @@
 379359
 0
 0
-0
 -.00000000000000527697
-- 
2.20.1

From 0039ba2ed457353376ed54994bfdac42ccffebe2 Mon Sep 17 00:00:00 2001
From: Gavin Howard <[email protected]>
Date: Fri, 21 Jun 2019 14:03:41 -0600
Subject: [PATCH] bc: fix a few bugs found in upstream

---
 toys/pending/bc.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/toys/pending/bc.c b/toys/pending/bc.c
index 7698a66b..5d0e98e9 100644
--- a/toys/pending/bc.c
+++ b/toys/pending/bc.c
@@ -536,6 +536,7 @@ BcStatus bc_lex_token(BcLex *l);
 
 BcStatus bc_parse_parse(BcParse *p);
 BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next);
+void bc_parse_noElse(BcParse *p);
 
 #define BC_PROG_ONE_CAP (1)
 
@@ -677,7 +678,7 @@ char *bc_err_msgs[] = {
 
   "negative number",
   "non integer number",
-  "overflow; %s",
+  "overflow",
   "divide by zero",
 
   "could not open file: %s",
@@ -3593,6 +3594,8 @@ static BcStatus bc_parse_endBody(BcParse *p, int brace) {
 
       new_else = (p->l.t == BC_LEX_KEY_ELSE);
       if (new_else) s = bc_parse_else(p);
+      else if (!has_brace && (!BC_PARSE_IF_END(p) || brace))
+        bc_parse_noElse(p);
     }
 
     if (brace && has_brace) brace = 0;
@@ -3602,6 +3605,15 @@ static BcStatus bc_parse_endBody(BcParse *p, int brace) {
 
   if (!s && p->flags.len == 1 && brace)
     s = bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
+  else if (brace && BC_PARSE_BRACE(p)) {
+    uint16_t flags = BC_PARSE_TOP_FLAG(p);
+    if (!(flags & (BC_PARSE_FLAG_FUNC_INNER | BC_PARSE_FLAG_LOOP_INNER)) &&
+        !(flags & (BC_PARSE_FLAG_IF | BC_PARSE_FLAG_ELSE)) &&
+        !(flags & (BC_PARSE_FLAG_IF_END)))
+    {
+      bc_vec_pop(&p->flags);
+    }
+  }
 
   return s;
 }
@@ -3612,7 +3624,7 @@ static void bc_parse_startBody(BcParse *p, uint16_t flags) {
   bc_vec_push(&p->flags, &flags);
 }
 
-static void bc_parse_noElse(BcParse *p) {
+void bc_parse_noElse(BcParse *p) {
   uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
   *flag_ptr = (*flag_ptr & ~(BC_PARSE_FLAG_IF_END));
   bc_parse_setLabel(p);
@@ -3971,8 +3983,10 @@ static BcStatus bc_parse_body(BcParse *p, int brace) {
     if (p->l.t == BC_LEX_NLINE) s = bc_lex_next(&p->l);
   }
   else {
+    size_t len = p->flags.len;
     s = bc_parse_stmt(p);
-    if (!s && !brace && !BC_PARSE_BODY(p)) s = bc_parse_endBody(p, 0);
+    if (!s && !brace && !BC_PARSE_BODY(p) && len <= p->flags.len)
+      s = bc_parse_endBody(p, 0);
   }
 
   return s;
@@ -4791,8 +4805,9 @@ static void bc_program_printString(char *str)
       if ((idx = stridx("ab\\efnqrt", c = str[i+1])) >= 0) {
         if (c == 'n') TT.nchars = SIZE_MAX;
         c = "\a\b\\\\\f\n\"\r\t"[idx];
-        i++;
       }
+      else putchar('\\');
+      i++;
     }
 
     putchar(c);
@@ -5668,6 +5683,7 @@ static void bc_vm_clean()
 static BcStatus bc_vm_process(char *text, int is_stdin) {
 
   BcStatus s;
+  uint16_t *flags;
 
   s = bc_parse_text(&BC_VM->prs, text);
   if (s) goto err;
@@ -5677,6 +5693,11 @@ static BcStatus bc_vm_process(char *text, int is_stdin) {
     if (s) goto err;
   }
 
+  flags = BC_PARSE_TOP_FLAG_PTR(&BC_VM->prs);
+
+  if (!is_stdin && BC_VM->prs.flags.len == 1 && *flags == BC_PARSE_FLAG_IF_END)
+    bc_parse_noElse(&BC_VM->prs);
+
   if (BC_PARSE_NO_EXEC(&BC_VM->prs)) goto err;
 
   s = bc_program_exec(&BC_VM->prog);
@@ -5832,7 +5853,7 @@ void bc_main(void)
     int i;
 
     for (i = 0; !s && i < toys.optc; ++i) s = bc_vm_file(toys.optargs[i]);
-    if (!s || s != BC_STATUS_QUIT) s = bc_vm_stdin();
+    if (!s) s = bc_vm_stdin();
   }
 
   if (CFG_TOYBOX_FREE) {
-- 
2.20.1

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to