Skip to content

Make BatchFile Testable#2618

Merged
kcgen merged 16 commits intomainfrom
mj/testable-batch-files
Jun 28, 2023
Merged

Make BatchFile Testable#2618
kcgen merged 16 commits intomainfrom
mj/testable-batch-files

Conversation

@MeAreJeenius
Copy link
Copy Markdown
Contributor

There shouldn't be any functional changes except for a fix for a crash when attempting to read a batch file without read permissions on that file.

@kcgen
Copy link
Copy Markdown
Member

kcgen commented Jun 21, 2023

Sorry for the delay @MeAreJeenius .. so heavy weight PRs moving through the pipes :-)

If you can look into the 'Checks' tab above:

https://github.com/dosbox-staging/dosbox-staging/pull/2618/checks

MacOS and Linux show a warning - which I think it causing link problems on Windows. Once that fixed it, CI should go green.

The refactoring and new tests look great!

Will get the review underway soon.

@MeAreJeenius
Copy link
Copy Markdown
Contributor Author

@kcgen
It looks like I don't have the needed permissions on the feature branch to push a rebase with my fixes. Can that be fixed?

@kcgen
Copy link
Copy Markdown
Member

kcgen commented Jun 21, 2023

@kcgen It looks like I don't have the needed permissions on the feature branch to push a rebase with my fixes. Can that be fixed?

Edit: looks like force-pushes are OK. Snipped out the noise to make way for PR-related signal :-)

@MeAreJeenius MeAreJeenius force-pushed the mj/testable-batch-files branch 2 times, most recently from d0232f2 to 110c882 Compare June 21, 2023 06:30
@dosbox-staging dosbox-staging deleted a comment from MeAreJeenius Jun 21, 2023
Comment thread src/shell/shell_misc.cpp Outdated
@kcgen kcgen added cleanup Non-functional changes that simplify, improve maintainability, or squash warnings tests Changes that verify code behavior labels Jun 21, 2023
@MeAreJeenius MeAreJeenius force-pushed the mj/testable-batch-files branch 4 times, most recently from df74de6 to b4122b1 Compare June 24, 2023 04:10
Comment thread include/shell.h
Comment thread include/shell.h
Comment thread src/hardware/serialport/serialport.cpp
Comment thread src/shell/command_line.cpp Outdated
Comment thread src/shell/shell.cpp
Comment thread src/shell/shell_misc.cpp Outdated
Comment thread include/shell.h
These functions were never used by the Program base class
@MeAreJeenius MeAreJeenius force-pushed the mj/testable-batch-files branch from b4122b1 to d7c150d Compare June 26, 2023 04:03
@kcgen
Copy link
Copy Markdown
Member

kcgen commented Jun 26, 2023

Just checked the CI results (see the 'checks' tab above).

  • PVS Studio - Download, extract, and open the PR's report versus main's report, and compare the shell_cmds.cpp; the PR adds one new issue versus main (I'm just looking at the counts)

  • MSVC reports 40 new warnings attributed to shell_*.cpp files:

      shell_cmds.cpp  : 38
      pdcscrn.cpp     : 5
      enet.h          : 5
      debug.c         : 3
      scr_dump.c      : 2
      slk.c           : 1
      shell_misc.cpp  : 1
      shell_batch.cpp : 1
      keyname.c       : 1
      instr.c         : 1
      initscr.c       : 1
      color.c         : 1
    
    Warnings grouped by type:
    
      C4996 : 55
      C4068 : 3
      C4244 : 2
    
    Total: 60 warnings (out of 20 allowed)
    

    I suspect the majority are #include related. Newly added .h and .cpp's should have the usual license text, #include dosbox.h followed by standard C++ includes and then project includes. Take a look at include/mouse.h and src/hardware/input/mouse.cpp to copy from :-)

Comment thread tests/batch_file_tests.cpp
@kcgen
Copy link
Copy Markdown
Member

kcgen commented Jun 26, 2023

All commits are building; bisect is healthy 👍

Using gcc native file: .github/meson/native-gcc-13.ini
Using clang native file: .github/meson/native-clang.ini
Compiling 45e355721 Add BatchFile tests                     .. gcc clang
Compiling 138ef6d07 Use HostShell interface in BatchFile    .. gcc clang
Compiling 6c2006b58 Change BatchFile constructor args to str.. gcc clang
Compiling ec888bd42 Delete move constructor and assigment ex.. gcc clang
Compiling d8cdeef26 Make BatchFiles contain their echo value.. gcc clang
Compiling b57858e7c Make a DOS_Shell function to handle Batc.. gcc clang
Compiling 5d687314c Replace DOS_Shell BatchFile pointer with.. gcc clang
Compiling fc90a638f Add HostShell interface                 .. gcc clang
Compiling bd0727e8c Replace BatchFile CommandLine pointer wi.. gcc clang
Compiling 57b4a6a3f Refactor CommandLine constructor        .. gcc clang
Compiling f5fe41b6e Move CommandLine implementation to its o.. gcc clang
Compiling 2c80d5186 Use ByteReader in BatchFile             .. gcc clang
Compiling c5f8bff2b Add ByteReader interface and FileReader .. gcc clang
Compiling 4c3b7b909 Format shell.h                          .. gcc clang
Compiling 84e87eb37 Move env functions from Program to DOS_S.. gcc clang

@MeAreJeenius MeAreJeenius force-pushed the mj/testable-batch-files branch 2 times, most recently from b11d4cf to 02cc16c Compare June 28, 2023 03:33
The FileReader class is a simple helper class that
reads the contents of a file and uses RAII to handle
its resources.

This class interface implements the ByteReader interface,
which allows for non-file implentations to be substituted
through polymorphism instead of having dependencies on the
concrete file reader. This is especially useful for tests.
Abstracts away file management in BatchFile.

Prevents a crash when attempting to read a file without
the necessary permissions.
Change the constructor to take string views
instead of const char*

Shorten constructor body
CommandLine doesn't currently need to be used
through polymorphism, so this avoids an allocation.
Allows classes which implement this to read value from an
environment without the hard requirement of a DOS_Shell.
Most useful for testing.
Previously, a BatchFile would store its parent Batchfile,
which would then set to the DOS_Shell's BatchFile pointer
upon destruction. Replacing this system with a stack of
BatchFiles makes this behaviour more intuitive and easier
to follow without changing the functionality.
RunInternal() and the BatchFile branch of the main loop mostly
overlapped, so they have been consolidated.
Previously, BatchFiles contained their parent's echo value,
which would then be applied to the shell upon destruction.
Having the BatchFile contain its own echo value makes it
easier to read and reason about.
Instead of having a hard dependency on DOS_Shell,
BatchFiles can use any class that can query an environment
variable. This makes the BatchFile class easier to test.
@MeAreJeenius MeAreJeenius force-pushed the mj/testable-batch-files branch from 02cc16c to d401845 Compare June 28, 2023 05:43
@MeAreJeenius
Copy link
Copy Markdown
Contributor Author

@kcgen
Those warnings were caused by me removing #include "dosbox.h" from shell.h.
Why does including that header suppress those warnings, which were about usage of cstring functions?
Why do we even want those suppressed?

@shermp
Copy link
Copy Markdown
Collaborator

shermp commented Jun 28, 2023

@kcgen Those warnings were caused by me removing #include "dosbox.h" from shell.h. Why does including that header suppress those warnings, which were about usage of cstring functions? Why do we even want those suppressed?

Because MSVC is overzealous in warning about using "unsafe" (but standard) c-string functions in favor of their own decidedly non-standard _s versions.

@kcgen kcgen merged commit ce46c29 into main Jun 28, 2023
@johnnovak johnnovak deleted the mj/testable-batch-files branch July 8, 2023 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Non-functional changes that simplify, improve maintainability, or squash warnings tests Changes that verify code behavior

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants