OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogserver commits / a3b3935

Echo is causing issues for guix; use printf
An alternative is `echo -e` but will that work? Aieee...
a3b3935167e1cb6a5c3efb93458dcd4b0523bc4a
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-17T06:50:29.000Z

Changed files (3) +39 -39

tests/shell/JsonShellUTest.cxxtest +11 -11
……@@ -94,7 +94,7 @@ public:
9494 logger().debug("BEGIN TEST: %s", __FUNCTION__);
9595
9696 // Test basic JSON shell interaction
97 std::string cmd = "echo 'json\n.\n' | nc -q 1 localhost " + std::to_string(port);
97 std::string cmd = "printf 'json\\n.\\n' | nc -q 1 localhost " + std::to_string(port);
9898 int rc = system(cmd.c_str());
9999 TS_ASSERT_EQUALS(rc, 0);
100100
……@@ -107,7 +107,7 @@ public:
107107
108108 // Test JSON query functionality with AtomSpace.version() using netcat
109109 std::string result = json_cmd_exec(
110 "echo 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335");
110 "printf 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335");
111111
112112 // The reply should contain a version number
113113 TS_ASSERT(result.size() > 0);
……@@ -122,7 +122,7 @@ public:
122122
123123 // Test JSON shell evaluation via netcat
124124 std::string result = json_cmd_exec(
125 "echo 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335");
125 "printf 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335");
126126
127127 TS_ASSERT(result.size() > 0);
128128 // The version should be a numeric string with a dot
……@@ -136,13 +136,13 @@ public:
136136 logger().debug("BEGIN TEST: %s", __FUNCTION__);
137137
138138 // First, add an atom using the Scheme shell
139 int rc = system("echo '(Concept \"test-concept-json\")' | nc -q 1 localhost 17335");
139 int rc = system("printf '(Concept \"test-concept-json\")\\n' | nc -q 1 localhost 17335");
140140 TS_ASSERT_EQUALS(rc, 0);
141141 usleep(50000);
142142
143143 // Test JSON shell can access the atom
144144 std::string result = json_cmd_exec(
145 "echo 'json\\nAtomSpace.haveNode(\"Concept\", \"test-concept-json\")\\n' | nc -q 1 localhost 17335");
145 "printf 'json\\nAtomSpace.haveNode(\"Concept\", \"test-concept-json\")\\n' | nc -q 1 localhost 17335");
146146
147147 printf("Do we have the node? result=>>>%s<<<\n", result.c_str());
148148 // Should return "true"
……@@ -156,20 +156,20 @@ public:
156156 logger().debug("BEGIN TEST: %s", __FUNCTION__);
157157
158158 // Add some atoms using the Scheme shell
159 int rc = system("echo '(Concept \"json-test-1\")' | nc -q 1 localhost 17335");
159 int rc = system("printf '(Concept \"json-test-1\")\\n' | nc -q 1 localhost 17335");
160160 TS_ASSERT_EQUALS(rc, 0);
161161 usleep(50000);
162 rc = system("echo '(Concept \"json-test-2\")' | nc -q 1 localhost 17335");
162 rc = system("printf '(Concept \"json-test-2\")\\n' | nc -q 1 localhost 17335");
163163 TS_ASSERT_EQUALS(rc, 0);
164164 usleep(50000);
165 rc = system("echo '(Number 42)' | nc -q 1 localhost 17335");
165 rc = system("printf '(Number 42)\\n' | nc -q 1 localhost 17335");
166166 TS_ASSERT_EQUALS(rc, 0);
167167 usleep(50000);
168168
169169 // Get all ConceptNodes via JSON shell
170170 // -q3 because the guix test environment is slow as molasses
171171 std::string result = json_cmd_exec(
172 "echo 'json\\nAtomSpace.getAtoms(\"ConceptNode\")\\n' | nc -q 3 localhost 17335");
172 "printf 'json\\nAtomSpace.getAtoms(\"ConceptNode\")\\n' | nc -q 3 localhost 17335");
173173
174174 printf("Did we get the Concepts? result=>>>%s<<<\n", result.c_str());
175175 TS_ASSERT(result.find("json-test-1") != std::string::npos);
……@@ -185,14 +185,14 @@ public:
185185 // Create a new atom via JSON command
186186 // -q3 because the guix test environment is slow as molasses
187187 std::string result = json_cmd_exec(
188 "echo 'json\\nAtomSpace.makeAtom({\"type\": \"Concept\", \"name\": \"json-created\"})\\n' | nc -q 3 localhost 17335");
188 "printf 'json\\nAtomSpace.makeAtom({\"type\": \"Concept\", \"name\": \"json-created\"})\\n' | nc -q 3 localhost 17335");
189189
190190 printf("Did we make the Concept? result=>>>%s<<<\n", result.c_str());
191191 TS_ASSERT(result.find("true") != std::string::npos);
192192
193193 // Verify the atom was created by checking with haveNode
194194 std::string verify = json_cmd_exec(
195 "echo 'json\\nAtomSpace.haveNode(\"Concept\", \"json-created\")\\n' | nc -q 3 localhost 17335");
195 "printf 'json\\nAtomSpace.haveNode(\"Concept\", \"json-created\")\\n' | nc -q 3 localhost 17335");
196196
197197 printf("Did verification work? verify=>>>%s<<<\n", result.c_str());
198198 TS_ASSERT(verify.find("true") != std::string::npos);
tests/shell/McpShellUTest.cxxtest +8 -8
……@@ -94,7 +94,7 @@ public:
9494 logger().debug("BEGIN TEST: %s", __FUNCTION__);
9595
9696 // Test basic MCP shell connection
97 int rc = system("echo 'mcp\n.\n' | nc -q 1 localhost 17334");
97 int rc = system("printf 'mcp\\n.\\n' | nc -q 1 localhost 17334");
9898 TS_ASSERT_EQUALS(rc, 0);
9999
100100 logger().debug("END TEST: %s", __FUNCTION__);
……@@ -106,7 +106,7 @@ public:
106106
107107 // Test MCP shell in server mode
108108 std::string reply = mcp_cmd_exec(
109 "echo 'mcp server localhost 8081\n.\n' | nc -q 1 localhost 17334");
109 "printf 'mcp server localhost 8081\\n.\\n' | nc -q 1 localhost 17334");
110110
111111 TS_ASSERT(reply.size() > 0);
112112 TS_ASSERT(reply.find("MCP shell") != std::string::npos);
……@@ -120,7 +120,7 @@ public:
120120
121121 // Test MCP shell in client mode
122122 std::string reply = mcp_cmd_exec(
123 "echo 'mcp client\n.\n' | nc -q 1 localhost 17334");
123 "printf 'mcp client\\n.\\n' | nc -q 1 localhost 17334");
124124
125125 TS_ASSERT(reply.size() > 0);
126126 TS_ASSERT(reply.find("MCP shell") != std::string::npos);
……@@ -134,7 +134,7 @@ public:
134134
135135 // Test MCP shell with hush mode
136136 std::string reply = mcp_cmd_exec(
137 "echo 'mcp hush\n' | nc -q 1 localhost 17334");
137 "printf 'mcp hush\\n' | nc -q 1 localhost 17334");
138138
139139 // Hush mode should return minimal output
140140 TS_ASSERT(reply.size() < 100);
……@@ -148,7 +148,7 @@ public:
148148
149149 // Test MCP ping via the shell using netcat
150150 std::string result = mcp_cmd_exec(
151 "echo 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"id\":1}\\n' | nc -q 1 localhost 17334");
151 "printf 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"id\":1}\\n' | nc -q 1 localhost 17334");
152152
153153 TS_ASSERT(result.size() > 0);
154154 // Verify it's a valid JSON-RPC response
……@@ -164,7 +164,7 @@ public:
164164
165165 // Test tools/list via the MCP shell using netcat
166166 std::string reply_str = mcp_cmd_exec(
167 "echo 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"tools/list\",\"id\":1}\\n' | nc -q 1 localhost 17334");
167 "printf 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"tools/list\",\"id\":1}\\n' | nc -q 1 localhost 17334");
168168
169169 // Verify the reply contains a valid JSON-RPC response
170170 TS_ASSERT(reply_str.find("{") != std::string::npos);
……@@ -181,14 +181,14 @@ public:
181181 logger().debug("BEGIN TEST: %s", __FUNCTION__);
182182
183183 // First, add an atom using the Scheme shell
184 int rc = system("echo '(Concept \"mcp-test-concept\")' | nc -q 1 localhost 17334");
184 int rc = system("printf '(Concept \"mcp-test-concept\")\\n' | nc -q 1 localhost 17334");
185185 TS_ASSERT_EQUALS(rc, 0);
186186 usleep(50000);
187187
188188 // Now use MCP shell to query for the atom
189189 // -q3 because the guix test environment is slow as molasses.
190190 std::string result = mcp_cmd_exec(
191 "echo 'mcp\\n{\"jsonrpc\": \"2.0\", \"method\": \"tools/call\", "
191 "printf 'mcp\\n{\"jsonrpc\": \"2.0\", \"method\": \"tools/call\", "
192192 "\"params\": {\"name\": \"getAtoms\", \"arguments\": {\"type\": \"ConceptNode\"}}, "
193193 "\"id\": 1}\\n' | nc -q 3 localhost 17334");
194194
tests/shell/ShellUTest.cxxtest +20 -20
……@@ -53,7 +53,7 @@ void gargleblast(int tid, int reps)
5353 {
5454 int j = i + 10 + (tid+10)*1000;
5555 char buf[1000];
56 sprintf(buf, "echo '(Evaluation (Predicate \"visible face\") (List (Number %d)))\n' | nc -q 1 localhost 17333", j);
56 sprintf(buf, "printf '(Evaluation (Predicate \"visible face\") (List (Number %d)))\\n' | nc -q 1 localhost 17333", j);
5757
5858 std::string reso = cmd_exec(buf);
5959
……@@ -94,7 +94,7 @@ void gargleblast(int tid, int reps)
9494
9595 if (20 <= i)
9696 {
97 sprintf(buf, "echo '(cog-extract! (Evaluation (Predicate \"visible face\") (List (Number %d))))\n' | nc -q 1 localhost 17333", j-20);
97 sprintf(buf, "printf '(cog-extract! (Evaluation (Predicate \"visible face\") (List (Number %d))))\\n' | nc -q 1 localhost 17333", j-20);
9898 std::string delo = cmd_exec(buf);
9999
100100 // The new half-open detection code sends blanks.
……@@ -256,23 +256,23 @@ public:
256256 {
257257 time_t t0 = time(0);
258258 logger().debug("BEGIN TEST: %s", __FUNCTION__);
259 int rc = system("echo '(Concept \"42\")\n' | nc -q 0 localhost 17333");
259 int rc = system("printf '(Concept \"42\")\\n' | nc -q 0 localhost 17333");
260260 if (rc != 0) printf("Error: first call failed\n");
261261 TS_ASSERT_EQUALS(rc, 0);
262262 usleep(50000);
263263
264264 // The hexadecimal \x4 is ctrl-D.
265 rc = system("echo 'scm\n(+ 2 2)\n\x4\n' | nc -q 0 localhost 17333");
265 rc = system("printf 'scm\\n(+ 2 2)\\n\x4\\n' | nc -q 0 localhost 17333");
266266 if (rc != 0) printf("Error: second call failed\n");
267267 TS_ASSERT_EQUALS(rc, 0);
268268 usleep(50000);
269269
270 rc = system("echo 'scm\n(Concept \"42\")\n' | nc -q 0 localhost 17333");
270 rc = system("printf 'scm\\n(Concept \"42\")\\n' | nc -q 0 localhost 17333");
271271 if (rc != 0) printf("Error: third call failed\n");
272272 TS_ASSERT_EQUALS(rc, 0);
273273 usleep(50000);
274274
275 rc = system("echo '(+ 2 2)\n.\n' | nc -q 0 localhost 17333");
275 rc = system("printf '(+ 2 2)\\n.\\n' | nc -q 0 localhost 17333");
276276 if (rc != 0) printf("Error: fourth call failed\n");
277277 TS_ASSERT_EQUALS(rc, 0);
278278 usleep(50000);
……@@ -290,7 +290,7 @@ public:
290290 // The hexadecimal \x16 is ctrl-C.
291291 // The interrupt should kill the sleep immediately.
292292 // Elapsed time should be well under a second.
293 int rc = system("echo '(sleep 42)\n\x16' | nc -q 0 localhost 17333");
293 int rc = system("printf '(sleep 42)\\n\x16' | nc -q 0 localhost 17333");
294294 if (rc != 0) logger().warn("Error: first call failed");
295295 TS_ASSERT_EQUALS(rc, 0);
296296
……@@ -300,7 +300,7 @@ public:
300300
301301 start = time(0);
302302 // The hexadecimal \x18 is ctrl-X aka "cancel"
303 rc = system("echo '(sleep 43)\n\x18' | nc -q 0 localhost 17333");
303 rc = system("printf '(sleep 43)\\n\x18' | nc -q 0 localhost 17333");
304304 if (rc != 0) logger().warn("Error: first call failed");
305305 TS_ASSERT_EQUALS(rc, 0);
306306
……@@ -310,7 +310,7 @@ public:
310310
311311 start = time(0);
312312 // The hexadecimal \x1b is ctrl-[ aka "escape"
313 rc = system("echo '(sleep 44)\n\x1b' | nc -q 0 localhost 17333");
313 rc = system("printf '(sleep 44)\\n\x1b' | nc -q 0 localhost 17333");
314314 if (rc != 0) logger().warn("Error: second call failed");
315315 TS_ASSERT_EQUALS(rc, 0);
316316
……@@ -332,16 +332,16 @@ public:
332332 time_t t0 = time(0);
333333 logger().debug("BEGIN TEST: %s", __FUNCTION__);
334334 cmd_exec(
335 "echo 'scm\n (sleep 3) (Concept \"A\")\n"
336 "(sleep 3)\n (Concept \"B\")\n"
337 "(sleep 3)\n (Concept \"C\")\n' | nc -q 0 localhost 17333");
335 "printf 'scm\\n (sleep 3) (Concept \"A\")\\n"
336 "(sleep 3)\\n (Concept \"B\")\\n"
337 "(sleep 3)\\n (Concept \"C\")\\n' | nc -q 0 localhost 17333");
338338
339339 // The barrier call here will force above to finish before the
340340 // atomspace print below. We sleep one second, to make sure the
341341 // above got started; we don't want the barrier to finish before
342342 // the above starts.
343343 sleep(1);
344 cmd_exec("echo 'scm\n (cog-global-barrier)' | nc -q 0 localhost 17333");
344 cmd_exec("printf 'scm\\n (cog-global-barrier)' | nc -q 0 localhost 17333");
345345
346346 // Sleep one second, so as to let the barrier at least get started,
347347 // before we ask to print the AtomSpace. The barrier should block
……@@ -350,7 +350,7 @@ public:
350350 // Use `nc -q 15` because it will take a while to respond.
351351 sleep(1);
352352 std::string ply = cmd_exec(
353 "echo 'scm\n (cog-prt-atomspace)' | nc -q 15 localhost 17333");
353 "printf 'scm\\n (cog-prt-atomspace)' | nc -q 15 localhost 17333");
354354
355355 // Expect between 189 and 205 bytes; it seems a trailing
356356 // prompt string is sometimes not received. I don't know
……@@ -395,17 +395,17 @@ public:
395395 {
396396 time_t t0 = time(0);
397397 logger().debug("BEGIN TEST: %s", __FUNCTION__);
398 std::string ply = cmd_exec("echo 'scm\n"
399 // "(add-to-load-path \"/usr/local/share/opencog/scm\")\n"
398 std::string ply = cmd_exec("printf 'scm\\n"
399 // "(add-to-load-path \"/usr/local/share/opencog/scm\")\\n"
400400 // "(use-modules (opencog) (opencog logger))"
401401 "(define (function-1 ticket) "
402402 // " (cog-logger-info \"CALLED function-1 ~s\" ticket)"
403 " (string-append \"return-1-\" ticket \"-finished\"))\n"
403 " (string-append \"return-1-\" ticket \"-finished\"))\\n"
404404 "(define (function-2 ticket) "
405405 // " (cog-logger-info \"CALLED function-2 ~s\" ticket)"
406 " (string-append \"return-2-\" ticket \"-finished\"))\n"
407 "(display \"Finished creating definitions\n\")"
408 "\n.\n' | nc -q 2 localhost 17333");
406 " (string-append \"return-2-\" ticket \"-finished\"))\\n"
407 "(display \"Finished creating definitions\\n\")"
408 "\\n.\\n' | nc -q 2 localhost 17333");
409409
410410 // The -q2 on `nc` should be enough for the above to finish up.
411411 TS_ASSERT (0 < ply.size());