From: Thomas Walker Lynch Date: Fri, 25 Oct 2024 08:11:56 +0000 (+0000) Subject: TestIO passes X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.js?a=commitdiff_plain;h=7833f8dead4a3d85ae76fb1f30facfb639f20dde;p=Mosaic TestIO passes --- diff --git a/developer/document/#question_jan.txt# b/developer/document/#question_jan.txt# deleted file mode 100644 index 9b0715c..0000000 --- a/developer/document/#question_jan.txt# +++ /dev/null @@ -1,2 +0,0 @@ - -On a directed acyclic graph, is it \ No newline at end of file diff --git a/developer/document/#variable_suffix_conventions.txt# b/developer/document/#variable_suffix_conventions.txt# deleted file mode 100644 index 8aca090..0000000 --- a/developer/document/#variable_suffix_conventions.txt# +++ /dev/null @@ -1,27 +0,0 @@ -# Suffix Conventions - -## Specify interface used with variable when clarification is useful: - -- `_set`: Indicates that the variable holds a set of items. - -- `_list`: Used for variables that represent a list of items. - -- `_f`: Refers to a function. - -Instead of making a variable name plural, add the interface qualifier: - - e.g. names -> name_set or name_list - -## Always a good idea to use these when working with files: - -- `_fp`: Refers to a file path. The part after the last slash is a file name. - -- `_dp`: Refers to a directory path. By convention, the value ends in a slash. - -- `_fn`: Refers to a file name. Value has no slashes. - -- `_dn`: Refers to a directory name. Value has no slashes. - -- `_fn_base`: The file name without the last dot and subsequent characters. - -- `_fn_ext`: The subsequent characters after the last dot in a file name. diff --git a/developer/shell/Mosaic b/developer/shell/Mosaic new file mode 100755 index 0000000..ba5b241 --- /dev/null +++ b/developer/shell/Mosaic @@ -0,0 +1,2 @@ +#!/bin/bash +java com.ReasoningTechnology."Mosaic".Mosaic diff --git a/developer/shell/build b/developer/shell/build deleted file mode 100755 index db43050..0000000 --- a/developer/shell/build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java com/ReasoningTechnology/"Mosaic"/build diff --git a/developer/tool/#release# b/developer/tool/#release# new file mode 100755 index 0000000..9ca9125 --- /dev/null +++ b/developer/tool/#release# @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# input guards + + if [ -z "$REPO_HOME" ]; then + echo "$(script_fp):: REPO_HOME is not set." + exit 1 + fi + + env_must_be="developer/tool/env" + if [ "$ENV" != "$env_must_be" ]; then + echo "$(script_fp):: error: must be run in the $env_must_be environment" + exit 1 + fi + +# script local environment + + release_dir="$REPO_HOME/release" + shell_dir="$REPO_HOME/developer/shell" + project_jar_fp="$REPO_HOME/developer/jvm/"$PROJECT".jar" + wrapper=$(shell_wrapper_list) + + + if [ ! -d "$release_dir" ]; then + mkdir -p "$release_dir" + fi + + # Function to copy and set permissions + install_file() { + source_fp="$1" + target_dp="$2" + perms="$3" + + target_file="$target_dp/$(basename "$source_fp")" + + if [ ! -f "$source_fp" ]; then + echo "install_file:: Source file '$source_fp' does not exist." + return 1 + fi + + if ! install -m "$perms" "$source_fp" "$target_file"; then + echo "Error: Failed to install $(basename "$source_fp") to $target_dp" + exit 1 + else + echo "Installed $(basename "$source_fp") to $target_dp with permissions $perms" + fi + } + +# do the release + + echo "Starting release process..." + + # Install the JAR file + install_file "$project_jar_fp" "$release_dir" "ug+r" + + # Install shell wrappers + for wrapper in $wrapper; do + install_file "$shell_dir/$wrapper" "$release_dir" "ug+r+x" + done + +echo "$(script_fp) done." diff --git a/developer/tool/clean_build_directories b/developer/tool/clean_build_directories index ed9e807..5165c3a 100755 --- a/developer/tool/clean_build_directories +++ b/developer/tool/clean_build_directories @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Removes all files found in the build directories. It asks no questions as to # how or why the files got there. Be especially careful with the 'shell' directory diff --git a/developer/tool/clean_javac_output b/developer/tool/clean_javac_output index 18fd312..88d8f3d 100755 --- a/developer/tool/clean_javac_output +++ b/developer/tool/clean_javac_output @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # remove all files created by make's call to `javac` # input guards diff --git a/developer/tool/clean_make b/developer/tool/clean_make deleted file mode 100755 index fc922dd..0000000 --- a/developer/tool/clean_make +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# remove all files made by `make` - -# input guards - - env_must_be="developer/tool/env" - if [ "$ENV" != "$env_must_be" ]; then - echo "$(script_fp):: error: must be run in the $env_must_be environment" - exit 1 - fi - -# wrappers to clean (this list space separated list will grow) - - wrapper=build - -# remove files - - set -x - cd "$REPO_HOME"/developer - rm -r scratch_pad/com/ReasoningTechnology/"$PROJECT" - rm jvm/"$PROJECT".jar - rm shell/{$wrapper} - set +x - -echo "$(script_fn) done." diff --git a/developer/tool/clean_make_output b/developer/tool/clean_make_output new file mode 100755 index 0000000..2a3acd5 --- /dev/null +++ b/developer/tool/clean_make_output @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# remove all files made by `make` + +# input guards + + env_must_be="developer/tool/env" + if [ "$ENV" != "$env_must_be" ]; then + echo "$(script_fp):: error: must be run in the $env_must_be environment" + exit 1 + fi + +# wrappers to clean (this list space separated list will grow) + + wrapper=$(shell_wrapper_list) + +# remove files + + set -x + cd "$REPO_HOME"/developer + rm -r scratch_pad/com/ReasoningTechnology/"$PROJECT" + rm jvm/"$PROJECT".jar + rm shell/{$wrapper} + set +x + +echo "$(script_fn) done." diff --git a/developer/tool/clean_release b/developer/tool/clean_release index 8ecb809..fc31cde 100755 --- a/developer/tool/clean_release +++ b/developer/tool/clean_release @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # remove files made by `make` and by `release` # input guards @@ -12,7 +12,7 @@ # things to clean release_dir="$REPO_HOME"/release - wrapper=build + wrapper=$(shell_wrapper_list) # remove files set -x diff --git a/developer/tool/make b/developer/tool/make index a21e0da..92e3ba2 100755 --- a/developer/tool/make +++ b/developer/tool/make @@ -35,7 +35,7 @@ echo "Creating JAR file..." echo "Creating shell wrappers..." mkdir -p shell # wrapper is a space separated list - wrapper=Mosaic + wrapper=$(shell_wrapper_list) for file in $wrapper;do cat > shell/$file << EOL #!/bin/bash diff --git a/developer/tool/release b/developer/tool/release index a123a14..8129f15 100755 --- a/developer/tool/release +++ b/developer/tool/release @@ -18,7 +18,7 @@ release_dir="$REPO_HOME/release" shell_dir="$REPO_HOME/developer/shell" project_jar_fp="$REPO_HOME/developer/jvm/"$PROJECT".jar" - wrapper=build + wrapper=$(shell_wrapper_list) if [ ! -d "$release_dir" ]; then diff --git a/developer/tool/shell_wrapper_list b/developer/tool/shell_wrapper_list new file mode 100755 index 0000000..67f7b2b --- /dev/null +++ b/developer/tool/shell_wrapper_list @@ -0,0 +1,14 @@ +#!/bin/env bash + +# input guards + + env_must_be="developer/tool/env" + if [ "$ENV" != "$env_must_be" ]; then + echo "$(script_fp):: error: must be run in the $env_must_be environment" + exit 1 + fi + + cd "$REPO_HOME"/developer + +# list of classes that have main calls and get shell wrappers +echo Mosaic diff --git a/document/readme.txt b/document/readme.txt index 3d32175..4a42a93 100644 --- a/document/readme.txt +++ b/document/readme.txt @@ -4,7 +4,7 @@ Mosaic A tool to assist in hierarchical white box testing. -Each piece of a program must have integrity for the complete picture to merge. +Each piece of a program must have integrity for the complete picture to emerge. With Mosaic we test the pieces, then the communication between the pieces. diff --git a/document/todo.txt b/document/todo.txt index ad6bd89..fc554b1 100644 --- a/document/todo.txt +++ b/document/todo.txt @@ -1,4 +1,6 @@ +Updates for Ariadne + 1. reflect project skeleton changes. replaced literal `Ariadne` with `$PROJECT` in top level env choices, PROJECT -> PROMPT_DECOR @@ -6,3 +8,15 @@ note in 'release' there is a variable name with the project name embedded in it: Ariadne_jar_fp -> project_jar_fp Change slashes to dots in the wrapper maker of 'make' + +2. should do something about `wrapper` as it appears in multiple places making + editing it a pain. + in all places `wrapper` appears, now calls `shell_wrapper_list` + in both developer and tester + +3. clean_make -> clean_make_output + +4. version outputs a `v` in front of the number + +5. fix many shebangs to be: #!/usr/bin/env bash + diff --git a/release/Mosaic b/release/Mosaic new file mode 100755 index 0000000..ba5b241 --- /dev/null +++ b/release/Mosaic @@ -0,0 +1,2 @@ +#!/bin/bash +java com.ReasoningTechnology."Mosaic".Mosaic diff --git a/release/Mosaic.jar b/release/Mosaic.jar index 02ea780..878a371 100644 Binary files a/release/Mosaic.jar and b/release/Mosaic.jar differ diff --git a/release/build b/release/build deleted file mode 100755 index db43050..0000000 --- a/release/build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java com/ReasoningTechnology/"Mosaic"/build diff --git a/tester/javac/Test0.java b/tester/javac/Test0.java new file mode 100644 index 0000000..8746515 --- /dev/null +++ b/tester/javac/Test0.java @@ -0,0 +1,37 @@ +package com.ReasoningTechnology.Mosaic.Test; +import com.ReasoningTechnology.Mosaic.Util; + +/* +Test Zero + +Plug it in, see if there is smoke. There usually is. + +*/ + +public class Test0{ + + public static boolean test_is_true(){ + return true; + } + + public static int run(){ + boolean[] condition = new boolean[1]; + condition[0] = test_is_true(); + + int i = 0; + if( !Util.all(condition) ){ + System.out.println("Test0 failed"); + return 1; + } + System.out.println("Test0 passed"); + return 0; + } + + // Main function to provide a shell interface for running tests + public static void main(String[] args){ + int return_code = run(); + System.exit(return_code); + return; + } + +} diff --git a/tester/javac/TestIO.java b/tester/javac/TestIO.java index a3c3509..1e0ecba 100644 --- a/tester/javac/TestIO.java +++ b/tester/javac/TestIO.java @@ -1,33 +1,70 @@ package com.ReasoningTechnology.Mosaic.Test; +import com.ReasoningTechnology.Mosaic.IO; import com.ReasoningTechnology.Mosaic.Util; -/* -Testing the IO class. +public class TestIO{ -*/ + public static int fut(){ + try{ + // Echo some characters from stdin to stdout + System.out.print((char) System.in.read()); + System.out.print((char) System.in.read()); + // Echo some more characters from stdin to stderr + System.err.print((char) System.in.read()); + System.err.print((char) System.in.read()); -public class TestIO{ + // Count remaining characters until EOF + int count = 0; + while( System.in.read() != -1 ){ + count++; + } - public static boolean test_is_true(){ - return true; + return count; + } catch( Exception e ){ + e.printStackTrace(); + return -1; // Error case + } } - + public static int run(){ - boolean[] condition = new boolean[5]; - conditionn[0] = test_is_true(); + IO io = new IO(); + String input_data = "abcdefg"; // Sample input + boolean[] condition = new boolean[3]; + + // Redirect IO streams + io.redirect_io(input_data); + + // Execute function under test + int result = fut(); + + // Check stdout content + String stdout = io.get_out_content().toString(); + condition[0] = stdout.equals("ab"); + + // Check stderr content + String stderr = io.get_err_content().toString(); + condition[1] = stderr.equals("cd"); + + // Check returned character count (3 remaining characters: 'e' ,'f' ,'g') + condition[2] = result == 3; + + // Restore original IO streams + io.restore_io(); - int i = 0; if( !Util.all(condition) ){ System.out.println("TestIO failed"); return 1; } + System.out.println("TestIO passed"); return 0; } // Main function to provide a shell interface for running tests - public static int main(String[] args){ - // tests currently accepts no arguments or options - return run(); // Calls the method to run all tests + public static void main(String[] args){ + int return_code = run(); + System.exit(return_code); + return; } -} + +} diff --git a/tester/jvm/TestBench.jar b/tester/jvm/TestBench.jar deleted file mode 100644 index fa385ca..0000000 Binary files a/tester/jvm/TestBench.jar and /dev/null differ diff --git a/tester/jvm/TestBenchMosaic.jar b/tester/jvm/TestBenchMosaic.jar new file mode 100644 index 0000000..17ab80c Binary files /dev/null and b/tester/jvm/TestBenchMosaic.jar differ diff --git a/tester/jvm/TestBenchMosaic_tester.jar b/tester/jvm/TestBenchMosaic_tester.jar deleted file mode 100644 index 41cabd0..0000000 Binary files a/tester/jvm/TestBenchMosaic_tester.jar and /dev/null differ diff --git a/tester/shell/Test0 b/tester/shell/Test0 new file mode 100755 index 0000000..e636935 --- /dev/null +++ b/tester/shell/Test0 @@ -0,0 +1,2 @@ +#!/bin/env bash +java com.ReasoningTechnology.Mosaic.Test.Test0 diff --git a/tester/shell/TestIO b/tester/shell/TestIO new file mode 100755 index 0000000..670538a --- /dev/null +++ b/tester/shell/TestIO @@ -0,0 +1,2 @@ +#!/bin/env bash +java com.ReasoningTechnology.Mosaic.Test.TestIO diff --git a/tester/shell/TestTestBench b/tester/shell/TestTestBench deleted file mode 100755 index 2afe32f..0000000 --- a/tester/shell/TestTestBench +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java com.ReasoningTechnology."Mosaic_tester".TestBench.TestTestBench diff --git a/tester/tool/clean_build_directories b/tester/tool/clean_build_directories index 2aff503..a3480cb 100755 --- a/tester/tool/clean_build_directories +++ b/tester/tool/clean_build_directories @@ -1,8 +1,9 @@ -#!/bin/bash +#!/usr/bin/env bash -# Caveat: the 'shell' directory is for built wrapper functions. `clean_build_directories` will -# remove all the files in this directory. For bespoke scripts used by the tester, put -# them in the `tool` directory. +# Caveat: the 'shell' directory is for built wrapper +# functions. `clean_build_directories` will remove all the files in this +# directory. For bespoke scripts used by the tester, put them in the `tool` +# directory. # input guards env_must_be="tester/tool/env" diff --git a/tester/tool/make b/tester/tool/make index 4a131f6..2c99c27 100755 --- a/tester/tool/make +++ b/tester/tool/make @@ -19,11 +19,11 @@ echo "Compiling files..." echo "Creating shell wrappers..." mkdir -p shell # wrapper is a space separated list - wrapper=TestTestBench + wrapper=$(shell_wrapper_list) for file in $wrapper;do cat > shell/$file << EOL #!/bin/env bash -java com.ReasoningTechnology."$PROJECT".Test.$file +java com.ReasoningTechnology.$PROJECT.Test.$file EOL chmod +x shell/$file done diff --git a/tester/tool/shell_wrapper_list b/tester/tool/shell_wrapper_list new file mode 100755 index 0000000..9d481fe --- /dev/null +++ b/tester/tool/shell_wrapper_list @@ -0,0 +1,12 @@ +#!/bin/bash + +# 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 + +# space separated list of shell interface wrappers +echo Test0 TestIO + diff --git a/tool/shell_wrapper_list b/tool/shell_wrapper_list new file mode 100755 index 0000000..9c7d827 --- /dev/null +++ b/tool/shell_wrapper_list @@ -0,0 +1,2 @@ +#!/bin/env bash +java com.ReasoningTechnology."Mosaic_tester".Test.shell_wrapper_list diff --git a/tool_shared/bespoke/cat_w_fn b/tool_shared/bespoke/cat_w_fn index 09931d1..f8d02cd 100755 --- a/tool_shared/bespoke/cat_w_fn +++ b/tool_shared/bespoke/cat_w_fn @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Check if at least one file is provided if [ $# -eq 0 ]; then diff --git a/tool_shared/bespoke/deprecate b/tool_shared/bespoke/deprecate index 821e7ab..124ffed 100755 --- a/tool_shared/bespoke/deprecate +++ b/tool_shared/bespoke/deprecate @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # cp subtree at under file path , and make all the copied # files read-only. The intended use case is for moving files to a `deprecated` diff --git a/tool_shared/bespoke/version b/tool_shared/bespoke/version index 53a64a6..5b99cbb 100755 --- a/tool_shared/bespoke/version +++ b/tool_shared/bespoke/version @@ -1,6 +1,5 @@ #!/bin/env bash -# 2024-10-24T14:56:09Z extracted from Ariadne - -echo 0.1 +# 2024-10-24T14:56:09Z project skeleton and test bench files extracted from Ariadne +echo v0.1 diff --git a/tool_shared/bespoke/wipe_release b/tool_shared/bespoke/wipe_release index 4b92b4b..d92cc88 100755 --- a/tool_shared/bespoke/wipe_release +++ b/tool_shared/bespoke/wipe_release @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # remove all files in the release directory set -e