private ByteArrayOutputStream out_content;
private ByteArrayOutputStream err_content;
private ByteArrayInputStream in_content;
- private boolean streams_foobar = false;
- private boolean uninitialized = true;
+ private Boolean streams_foobar = false;
+ private Boolean uninitialized = true;
// IO currently has no constructors defined, uses default
// functions are used.
//
// This is the only method that can set the streams_foobar flag.
- public boolean redirect(){
+ public Boolean redirect(){
try{
original_out = System.out;
System.setIn(in_content);
}
- public boolean has_out_content(){
+ public Boolean has_out_content(){
if(streams_foobar){
throw new IllegalStateException
(
return out_content.toString();
}
- public boolean has_err_content(){
+ public Boolean has_err_content(){
if(streams_foobar){
throw new IllegalStateException
(
public class Mosaic{
- public static boolean test_is_true(){
+ public static Boolean test_is_true(){
return true;
}
private static ByteArrayOutputStream err_content;
private static InputStream in_content;
- public static boolean method_is_wellformed(Method method) {
- // Check if the method returns boolean
- if(!method.getReturnType().equals(boolean.class)){
- System.out.println("Structural problem: " + method.getName() + " does not return boolean.");
+ public static Boolean method_is_wellformed(Method method) {
+ // Check if the method returns Boolean
+ if(!method.getReturnType().equals(Boolean.class)){
+ System.out.println("Structural problem: " + method.getName() + " does not return Boolean.");
return false;
}
return true;
}
- public static boolean run_test(Object test_suite ,Method method ,IO io){
+ public static Boolean run_test(Object test_suite ,Method method ,IO io){
String test_name = method.getName();
// Ways a test can fail, these are not generally singularly exclusive.
- boolean fail_TestBench = false;
- boolean fail_malformed = false;
- boolean fail_reported = false;
- boolean fail_exception = false;
- boolean fail_extraneous_stdout = false;
- boolean fail_extraneous_stderr = false;
+ Boolean fail_TestBench = false;
+ Boolean fail_malformed = false;
+ Boolean fail_reported = false;
+ Boolean fail_exception = false;
+ Boolean fail_extraneous_stdout = false;
+ Boolean fail_extraneous_stderr = false;
String exception_string = "";
}
// redirect I/O to an io instance
- boolean successful_redirect = io.redirect();
+ Boolean successful_redirect = io.redirect();
if( successful_redirect ){
io.clear_buffers(); // start each test with nothing on the I/O buffers
}else{
}
// return condition
- boolean test_failed =
+ Boolean test_failed =
fail_reported
|| fail_exception
|| fail_extraneous_stdout
}
// True when it does a search and finds a true value; otherwise false.
- public static boolean exists( Object[] elements ){
+ public static Boolean exists( Object[] elements ){
return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null;
}
// True when it does a search and does not find a false value; otherwise false.
- public static boolean all( Object[] elements ){
+ public static Boolean all( Object[] elements ){
return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null;
}
- public static void all_set_false(boolean[] conditions){
- for(boolean condition : conditions) condition = false;
+ public static void all_set_false(Boolean[] conditions){
+ for(Boolean condition : conditions) condition = false;
}
- public static void all_set_true(boolean[] conditions){
- for(boolean condition : conditions) condition = true;
+ public static void all_set_true(Boolean[] conditions){
+ for(Boolean condition : conditions) condition = true;
}
public static String iso_utc_time(){
--- /dev/null
+#!/bin/bash
+java com.ReasoningTechnology."Mosaic".Mosaic
+About `jdb`
-1. location
+1. setting the environment
- jdb will be in the third_party tools directory:
+ The environment should be set before running the IDE. For example,
+
+ > cd Mosaic
+ > source env_tester
+ > emacs &
+
+ (I use emacs as my IDE. You might be using a different tool.)
+
+2. location of the executable
+
+ Provided that the project administrator installed it, jdb is located in the
+ third_party tools directory. In the tester environment the variable
+ `JAVA_HOME` should hold the jdb directory path, and this should already
+ be in the `PATH`. For example:
+
+ > echo $ENV
+ tester/tool/env
+
+ > echo $JAVA_HOME
+ /var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11
- 2024-10-27T09:34:37Z[Mosaic_tester]
- Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§
> which jdb
/var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin/jdb
-2. IDE and the environment
+3. invocation from a shell command:
- The environment must be set before running the IDE or the IDE will not
- have access to it.
+ jdb -sourcepath $SOURCEPATH <class_name>
- For example Emacs will be following the PATH as it was when Emacs
- was invoked, for file completion in the Emacs shell, etc. Even when
- the environment is set in a shell running inside of emacs.
+ The `SOURCEPATH` is assigned a value in `tester/tool/env`. In some versions
+ of jdb there is no space between `-sourcepath` and the `$SOURCDEPATH`.
- FYI, the path can be fixed but other environment settings will still be missing.
- (setenv "PATH" (concat (getenv "PATH") ":<directory>"))
- (setq exec-path (append exec-path '("<directory")))
+ jdb will read CLASSPATH from the environment. In contrast jdb will not read
+ `SOURCEPATH` from the environment. It must be passed as an argument.
-3. command line:
+ There is a `run_jdb` script in the `tool` directory.
- SOURCEPATH must be defined in advance. There is no space between -source and the
- source path. Typically SOURCEPATH will be `javac`.
+4. invocation inside of Emacs
- jdb -sourcepath $SOURCEPATH <class_name>
+ The file `tool_shared/bespoke/emacs.el` holds a definition for the `jdbx`
+ command. This command will read the SOURCEPATH from the environment and run
+ jdb in Emacs.
- currently, in emacs, e.g.:
- jdb -sourcepathjavac Test_Util
+ That file also holds the definition for a listener to the jdb `sourcepath`
+ command.
- When invoked from Emacs M-x jdb, there is no space between the -sourcepath and
- the $SOURCEPATH.
- In jdb run from gud-gdb, when packages are used, the SOURCEPATH is the path
- to the directory that holds a directory tree, where said directory tree
- parallels the package name. Otherwise it is the directory path to the source
- directory. Note the `distribute_sources` script.
- When using packages, the <class_name> is fully qualified.
public class Test0{
- public static boolean test_is_true(){
+ public static Boolean test_is_true(){
return true;
}
public static int run(){
- boolean[] condition = new boolean[1];
+ Boolean[] condition = new Boolean[1];
condition[0] = test_is_true();
int i = 0;
TestSuite(){
}
- public boolean test_pass(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
+ public Boolean test_pass(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
return true;
}
- public boolean test_fail_0(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
+ public Boolean test_fail_0(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
return false;
}
// Tests if exception uncaught by the test correctly causes a failure from the TestBench.
- public static boolean test_fail_1() throws Exception {
+ public static Boolean test_fail_1() throws Exception {
int randomInt = (int) (Math.random() * 100); // Generate a random integer
// Always returns true, but Java will not complain that following code is unreachable
if(
public static int run(){
IO io = new IO();
- boolean[] condition = new boolean[3];
+ Boolean[] condition = new Boolean[3];
// Redirect IO streams
io.redirect();
public class Test_Util{
- public static boolean test_all(){
+ public static Boolean test_all(){
// Test with zero conditions
- boolean[] conditions0 = {};
- boolean result = !Util.all(conditions0); // Empty conditions list is false.
+ Boolean[] conditions0 = {};
+ Boolean result = !Util.all(conditions0); // Empty conditions list is false.
// Test with one condition
- boolean[] conditions1_true = {true};
- boolean[] conditions1_false = {false};
+ Boolean[] conditions1_true = {true};
+ Boolean[] conditions1_false = {false};
result &= Util.all(conditions1_true); // should return true
result &= !Util.all(conditions1_false); // should return false
// Test with two conditions
- boolean[] conditions2_true = {true, true};
- boolean[] conditions2_false1 = {true, false};
- boolean[] conditions2_false2 = {false, true};
- boolean[] conditions2_false3 = {false, false};
+ Boolean[] conditions2_true = {true, true};
+ Boolean[] conditions2_false1 = {true, false};
+ Boolean[] conditions2_false2 = {false, true};
+ Boolean[] conditions2_false3 = {false, false};
result &= Util.all(conditions2_true); // should return true
result &= !Util.all(conditions2_false1); // should return false
result &= !Util.all(conditions2_false2); // should return false
result &= !Util.all(conditions2_false3); // should return false
// Test with three conditions
- boolean[] conditions3_false1 = {true, true, false};
- boolean[] conditions3_true = {true, true, true};
- boolean[] conditions3_false2 = {true, false, true};
- boolean[] conditions3_false3 = {false, true, true};
- boolean[] conditions3_false4 = {false, false, false};
+ Boolean[] conditions3_false1 = {true, true, false};
+ Boolean[] conditions3_true = {true, true, true};
+ Boolean[] conditions3_false2 = {true, false, true};
+ Boolean[] conditions3_false3 = {false, true, true};
+ Boolean[] conditions3_false4 = {false, false, false};
result &= !Util.all(conditions3_false1); // should return false
result &= Util.all(conditions3_true); // should return true
result &= !Util.all(conditions3_false2); // should return false
return result;
}
- public static boolean test_all_set_false(){
- boolean[] conditions = {true, true, true};
+ public static Boolean test_all_set_false(){
+ Boolean[] conditions = {true, true, true};
Util.all_set_false(conditions);
return !Util.all(conditions); // Should return false after setting all to false
}
- public static boolean test_all_set_true(){
- boolean[] conditions = {false, false, false};
+ public static Boolean test_all_set_true(){
+ Boolean[] conditions = {false, false, false};
Util.all_set_true(conditions);
return Util.all(conditions); // Should return true after setting all to true
}
public static int run(){
- boolean[] condition = new boolean[3];
+ Boolean[] condition = new Boolean[3];
condition[0] = test_all();
condition[1] = test_all_set_false();
condition[2] = test_all_set_true();
+++ /dev/null
-#!/bin/env bash
-script_afp=$(realpath "${BASH_SOURCE[0]}")
-
-# input guards
-env_must_be="tester/tool/env"
-if [ "$ENV" != "$env_must_be" ]; then
- echo "$(script_fp):: error: must be run in the $env_must_be environment"
- exit 1
-fi
-
-jdb -sourcepath "$SOURCEPATH" "$@"
-
fi
jdb -sourcepath "$SOURCEPATH" "$@"
+
# Check if at least one file is provided
if [ $# -eq 0 ]; then
- echo "Usage: $0 <filename1> [filename2] ..."
+ echo "Usage: $(script_fp) <filename1> [filename2] ..."
exit 1
fi
--- /dev/null
+
+; The first time Emacs encounters a link to a source file, Emacs asks if it should follow it.
+; This might suppress that initial question and follow the link.
+; (setq find-file-visit-truename t)
+
+(defun jdbx ()
+ "Set gud-jdb-sourcepath from the environment and run jdb with the correct source path."
+ (interactive)
+ (let*
+ (
+ (sourcepath (getenv "SOURCEPATH"))
+ )
+ (if
+ sourcepath
+ (setq gud-jdb-sourcepath (split-string sourcepath ":" t))
+ (message "Warning: SOURCEPATH is not set. `jdb` will run without source path information.")
+ )
+ (let
+ (
+ (class-name (read-string "Enter the class to debug: " "Test_Util"))
+ )
+ (jdb (concat "jdb -sourcepath"
+ (if
+ sourcepath
+ (mapconcat 'identity gud-jdb-sourcepath ":") ""
+ )
+ " "
+ class-name
+ )
+ ))))
+
+(defun monitor-jdb-sourcepath (output)
+ "Monitor the jdb output for `sourcepath ARG` commands and update `gud-jdb-sourcepath` with each path in ARG."
+ (when
+ (string-match "sourcepath \\(.+\\)" output)
+ (let*
+ (
+ (new-paths (match-string 1 output))
+ (paths-list (split-string new-paths ":" t))
+ )
+ ;; Add each path in paths-list to gud-jdb-sourcepath if not already present
+ (dolist
+ (path paths-list)
+ (unless
+ (member path gud-jdb-sourcepath)
+ (setq gud-jdb-sourcepath (append gud-jdb-sourcepath (list path)))
+ )
+ )
+ (message "Updated gud-jdb-sourcepath: %s" gud-jdb-sourcepath)))
+ output)
+
+(add-hook 'gud-filter-functions 'monitor-jdb-sourcepath)