A command testing method, computing device, and storage medium
By analyzing the command and setting the command return logic, the problem that the status code in the prior art cannot accurately reflect the command execution situation, and the accurate labeling of the command execution situation and the reliability of the test results are achieved.
Patent Information
- Application Number
- CN202210505629.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-10
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-05-10
AI Technical Summary
In the prior art, the status code returned by the execution command cannot accurately reflect the command execution situation, especially when the command contains a connector, the return value of the status code is interfered with multiple interference, resulting in the test results being unreliable.
By analyzing the commands to be tested, determining whether they include connectors and query commands, setting the command return logic according to different situations, executing the command and returning the status code to ensure the accuracy of the status code.
It realizes accurate labeling of command execution, avoids interference with status codes by connectors and query commands, and improves the reliability of test results.
Smart Images

Figure CN114880225B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing, and particularly to a command testing method, a computing device, and a storage medium. Background Art
[0002] With the development of computer technology, people use more and more applications or files in computers to complete work, and most applications need to perform various debugging tasks. When debugging an application or checking a file, various commands are usually used for testing; by judging the status code returned by the executed command, it can be determined whether the application or file is normal or abnormal. In the prior art, the status code returned by the executed command sometimes cannot accurately reflect the execution situation of the command.
[0003] Therefore, a new command testing method is needed. Summary of the Invention
[0004] Therefore, the present invention provides a command testing method in an attempt to solve or at least alleviate the problems mentioned above.
[0005] According to a first aspect of the present invention, there is provided a command testing method suitable for execution in a computing device. The method includes the steps of: parsing a command to be tested to determine whether the command includes a separator and a query command; if the command does not include a separator and a query command, executing the command to obtain a status code; if the status code is a first status code indicating normal execution of the command, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing.
[0006] Optionally, in the method according to the present invention, it further includes the step of: if the command is an incorrect command, modifying the status code to a second status code and returning it to indicate failed testing.
[0007] Optionally, in the method according to the present invention, it further includes the step of: if the status code is a second status code indicating abnormal execution of the command, determining whether the command is a correct command; if the command is a correct command, returning the second status code to indicate failed testing.
[0008] Optionally, in the method according to the present invention, it further includes the step of: if the command is an incorrect command, modifying the status code to the first status code and returning it to indicate successful testing.
[0009] According to a second aspect of the present invention, there is provided a command testing method suitable for execution in a computing device. The method includes the steps of: parsing a command to be tested to determine whether the command includes a query command; if the command includes a query command, executing the command to obtain a status code; if the status code is the first status code, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing.
[0010] Optionally, in the method according to the present invention, the method further includes the step of: if the command is an incorrect command, modifying the status code to a second status code and returning it, indicating that the test fails.
[0011] Optionally, in the method according to the present invention, the method further includes the step of: if the status code is the second status code, determining whether the command is a correct command; if the command is a correct command, determining whether the output content of the command is empty; if the output content of the command is empty, modifying the status code to a first status code and returning it, indicating that the test is successful.
[0012] Optionally, in the method according to the present invention, the method further includes the step of: if the output content of the command is not empty, returning the second status code, indicating that the test fails.
[0013] Optionally, in the method according to the present invention, the method further includes the step of: if the command is an incorrect command, determining whether the output content of the command is empty; if the output content of the command is empty, returning the second status code, indicating that the test fails.
[0014] Optionally, in the method according to the present invention, the method further includes the step of: if the output content of the command is not empty, modifying the status code to a first status code and returning it, indicating that the test is successful.
[0015] According to a third aspect of the present invention, there is provided a command testing method, which is suitable for being executed in a computing device. The method includes the steps of: parsing a command to be tested to determine whether the command includes a separator and a query command; if the command includes a separator, setting a command return logic and executing the command to obtain a status code; if the status code is a first status code, determining whether the command is a correct command; if the command is a correct command, returning the first status code, indicating that the test is successful.
[0016] Optionally, in the method according to the present invention, the method further includes the step of: if the command is an incorrect command, modifying the status code to a second status code and returning it, indicating that the test fails.
[0017] Optionally, in the method according to the present invention, the method further includes the step of: if the status code is the second status code, determining whether the command is a correct command; if the command is a correct command, returning the second status code, indicating that the test fails.
[0018] Optionally, in the method according to the present invention, the method further includes the step of: if the command is an abnormal command, modifying the status code to a first status code and returning it, indicating that the test is successful.
[0019] According to a fourth aspect of the present invention, there is provided a command testing method suitable for execution in a computing device. The method includes the steps of: parsing the command to be tested to determine whether the command includes a conjunction and a query command; if the command includes a conjunction and a query command, setting a command return logic and executing the command to obtain a status code; determining whether the query command is the last command in the command; if the query command is not the last command in the command and the status code is a first status code, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing.
[0020] Optionally, in the method according to the present invention, the method further includes the steps of: if the command is an incorrect command, modifying the status code to a second status code and returning it to indicate failed testing.
[0021] Optionally, in the method according to the present invention, the method further includes the steps of: if the query command is not the last command in the command and the status code is a second status code, returning the second status code.
[0022] Optionally, in the method according to the present invention, the method further includes the steps of: if the query command is the last command in the command, determining whether the intermediate status code before executing the query command is a first status code; if the intermediate status code is not a first status code, returning the second status code to indicate failed testing.
[0023] Optionally, in the method according to the present invention, the method further includes the steps of: if the intermediate status code is a first status code and the status code is also a first status code, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing.
[0024] Optionally, in the method according to the present invention, the method further includes the steps of: if the command is an incorrect command, modifying the status code to a second status code and returning it to indicate failed testing.
[0025] Optionally, in the method according to the present invention, the method further includes the steps of: if the intermediate status code is a first status code and the status code is a second status code, determining whether the command is a correct command; if the command is a correct command, returning the second status code to indicate failed testing.
[0026] Optionally, in the method according to the present invention, the method further includes the steps of: if the command is an incorrect command, modifying the status code to a first status code and returning it to indicate successful testing.
[0027] Optionally, in the method according to the present invention, the command return logic includes: if the sub-command status code returned by the execution of one or more sub-commands in the command is a second status code, the status code is a second status code.
[0028] Optionally, in the method according to the present invention, it further includes the step of: after returning the first status code or the second status code, deleting the command return logic.
[0029] Optionally, in the method according to the present invention, it further includes the step of: when returning the first status code or the second status code, returning the output content of the command.
[0030] Optionally, in the method according to the present invention, the query command includes: the grep command.
[0031] Optionally, in the method according to the present invention, the connector includes a pipe symbol.
[0032] According to a fifth aspect of the present invention, there is provided a computing device, including: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include those for executing the command testing method according to the present invention.
[0033] According to a sixth aspect of the present invention, there is provided a computer-readable storage medium storing one or more programs, the one or more programs including instructions which, when executed by a computing device, cause the computing device to execute the command testing method according to the present invention.
[0034] The present invention discloses a command testing method, which is suitable for being executed in a computing device. One or more applications are running in the computing device. The method includes the steps of: parsing the command to be tested to determine whether the command includes a connector and a query command; if the command includes a connector and a query command, setting the command return logic and executing the command to obtain a status code; determining whether the query command is the last command in the command; if the query command is not the last command in the command and the status code is the first status code indicating normal command execution, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing. By parsing the command and determining whether it includes a connector and a query command, the present invention returns a status code according to the corresponding judgment logic, so as to accurately indicate the command execution situation with the status code. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] To achieve the above and related purposes, certain illustrative aspects are described herein in connection with the following description and drawings, which indicate various ways in which the principles disclosed herein can be practiced, and all aspects and their equivalent aspects are intended to fall within the scope of the claimed subject matter. By reading the following detailed description in conjunction with the drawings, the above and other objects, features, and advantages of the present disclosure will become more apparent. Throughout the present disclosure, the same reference numerals generally refer to the same components or elements.
[0036] Figure 1 FIG. 1 shows a schematic diagram of a computing device 100 according to an exemplary embodiment of the present invention;
[0037] Figure 2 FIG. 2 shows a schematic flowchart of a command testing method 200 according to an exemplary embodiment of the present invention;
[0038] Figure 3 FIG. 3 shows a schematic diagram of parsing a command to be tested according to an exemplary embodiment of the present invention;
[0039] Figure 4 FIG. 4 shows a schematic diagram of a first process according to an exemplary embodiment of the present invention;
[0040] Figure 5 FIG. 5 shows a schematic diagram of a second process according to an exemplary embodiment of the present invention;
[0041] Figure 6 FIG. 6 shows a schematic diagram of a third process according to an exemplary embodiment of the present invention;
[0042] Figure 7 FIG. 7 shows a schematic diagram of a fourth process according to an exemplary embodiment of the present invention;
[0043] Figure 8 FIG. 8 shows a schematic diagram of the execution result of a test case according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be fully conveyed to those skilled in the art. The same reference numerals generally refer to the same components or elements.
[0045] First, refer to Figure 1 , Figure 1 FIG. 1 shows a schematic diagram of a computing device 100 according to an exemplary embodiment of the present invention. As Figure 1As shown, the computing device 100 includes an internal memory 111, an external memory 112, a central processing unit 113, and a graphics processing unit 114. The internal memory 111 includes, but is not limited to, volatile storage (e.g., random access memory), non-volatile storage (e.g., read-only memory), flash memory, or any combination of such memories. The external memory 112 refers to storage other than the internal memory 111 and the cache of the central processing unit 113, and can be specifically implemented as a hard disk, a floppy disk, an optical disc, a USB flash drive, etc. The central processing unit 113 is the arithmetic core and control core of the computing device 100, and is used to parse computer instructions and process data in computer software. The graphics processing unit 114 is a microprocessor that performs image and graphics-related computing work in the computing device.
[0046] Based on the above components, the computing device 100 also runs an operating system 120, which is suitable for controlling the operation of the computing device 100. In addition, the examples are practiced in combination with a graphics library, other operating systems, or any other application programs, and are not limited to any specific application or system. The present invention does not limit the specific type of the operating system 120.
[0047] One or more applications can also be run on the computing device 100 based on the operating system 120, such as Figure 1 the applications 131 to 133 shown. The present invention does not limit the number and types of applications running on the computing device 100. For example, the applications can be implemented as: email and contact applications, word processing applications, spreadsheet applications, database applications, slide show applications, painting or computer-aided applications, web browser applications, etc.
[0048] The operating system 120 includes a kernel 121 and a shell module 122. The kernel 121 provides functions such as process management and memory management in the operating system 120. According to an embodiment of the present invention, when the operating system 120 is a Linux system, the kernel 121 is a Linux kernel.
[0049] The shell module 122 is software that provides users with access to the operating system, and users can use the operating system through the shell module.
[0050] According to one aspect, the computing device 100 may also be connected to one or more input devices 141, such as a keyboard, a mouse, a pen, a voice input device, a touch input device, etc. One or more output devices 114, such as a display, a speaker, a printer, etc. may also be connected. The foregoing devices are examples and other devices may also be used. The computing device 100 may include one or more communication connections that allow communication with other computing devices. Examples of suitable communication connections include, but are not limited to: RF transmitter, receiver, and / or transceiver circuits; Universal Serial Bus (USB), parallel, and / or serial ports.
[0051] Embodiments of the present invention also provide a non-transitory readable storage medium storing instructions for causing the computing device to execute the method according to embodiments of the present invention. The readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. The information may be computer-readable instructions, data structures, program modules, or other data. Examples of readable storage media include, but are not limited to: Phase Change Memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technologies, Compact Disc Read Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transitory readable storage medium.
[0052] According to one aspect, the communication medium is implemented by computer-readable instructions, data structures, program modules, or other data in a modulated data signal (e.g., a carrier wave or other transmission mechanism), and includes any information delivery medium. According to one aspect, the term "modulated data signal" describes a signal having one or more characteristic sets or a signal that has been altered in a manner that encodes information in the signal. By way of example and not limitation, communication media include wired media such as a wired network or a direct wired connection, and wireless media such as acoustic, radio frequency (RF), infrared, and other wireless media.
[0053] In the prior art, the system can be tested using shell commands through the shell module 122, and it is determined whether the system response meets the expectation by the status code returned after the instruction execution. The status code refers to a specific field used to identify the execution situation of a command, and different status codes represent different command execution situations. For example, it can be defined that the status code 0 represents the situation where the command ends successfully; the status code 1 represents the situation where a general location error is encountered during the command execution.
[0054] However, in the prior art, there may be a phenomenon that the returned command execution status code cannot accurately identify the command execution situation.
[0055] For example: Build shell script 1 to implement a test scenario: Insert the content "True" into the file testfile1.
[0056] The following expected results may occur during command execution:
[0057] The keyword "True" is included in the file testfile1, and the result of successful insertion is obtained;
[0058] The keyword "True" is not included in the file testfile1, and the result of failed insertion is obtained.
[0059] The specific shell script 1 used for testing is as follows:
[0060] #! / bin / bash
[0061] echo True>testfile1
[0062] echo "
Scenario 1
[0063] cat testfile1|grep True; echo -e "\nCommand execution status: $?"
[0064] echo "___________________"
[0065] echo "
Scenario 2
[0066] cat testfile1|grep False; echo -e "\nCommand execution status: $?"
[0067] echo "___________________"
[0068] echo "
Scenario 3
[0069] cat testfile2|grep False; echo -e "\nCommand execution status: $?"
[0070] echo "___________________"
[0071] The results obtained by executing the above test script are as follows:
[0072]
Scenario 1
[0073] True
[0074] Command execution status code: 0
[0075]
Scenario 2
[0076] Command execution status code: 1
[0077]
Scenario 3
[0078] cat: testfile2: No such file or directory
[0079] Command execution status code: 1
[0080] From the command execution results of executing the shell script under
Scenario 1
Scenario 2
Scenario 3
Scenario 2
Scenario 3
[0081] If subsequent tests are conducted for this scenario and the expected result assertion is that the test passes when the result is not 0, then for
Scenario 3
[0082] Moreover, if the command also includes connectors, the connectors will also affect the status code obtained from the executed command, and the test command and the connectors will jointly cause multiple interferences. For example, when the command includes the "grep" command and the pipe symbol, it will affect the finally obtained status code. A connector refers to when multiple commands need to be executed at once, connectors can be used to connect the commands. Connectors include the pipe symbol, semicolon (;), logical AND (&&), and logical OR (||), etc. Connecting two or more commands (programs or processes) together and using the output of one command as the input of the next command, two or more commands connected in this way form a pipeline. The function of the pipe symbol (|) is: when connecting multiple commands, the correct output of the previous command execution will be handed over to the next command for further processing. If the previous command execution fails, an error will be reported. If the next command cannot process the output of the previous command, an error will also be reported.
[0083] The following is an example using pure pipeline commands:
[0084] Build shell script 2 to implement the test scenario: Print the content of file testfile1, and at the same time display the content with "True" replaced by "False".
[0085] The specific shell script 2 used for testing is as follows:
[0086] #! / bin / bash
[0087] echo True>testfile1
[0088] echo "
Scenario 4
[0089] cat testfile1|sed‘s / True / False / g’; echo -e "\nCommand execution status: $?"
[0090] echo "___________________"
[0091] echo "
Scenario 5
[0092] cat testfile2|sed‘s / True / False / g’; echo -e "\nCommand execution status: $?"
[0093] echo "___________________"
[0094] rm -f testfile1
[0095] The results obtained by executing the above test script are as follows:
[0096]
Scenario 4
[0097] False
[0098] Command execution status code: 0
[0099]
Scenario 5
[0100] cat: testfile2: No such file or directory
[0101] Command execution status code: 0
[0102] As can be seen from [Scenario 4] and [Scenario 5], when the command contains a pipe symbol (|), the return value of the status code is based on the return value of the last command; even if the status code of the command before the pipe symbol is non-zero, the final status code will still be obtained according to the execution of the command after the pipe symbol. Therefore, from the perspective of the status code, it is impossible to identify command anomalies, which is the same as [Scenario 3].
[0103] The situations exemplified above have a high probability of occurring in actual testing work. In addition to human reasons: code writing errors or lack of experience, for example, updates to dependent tools / requirement changes, which lead to changes in commands / parameters, will also cause deviations in test results. If the number of test cases is large and the development time becomes longer, the hidden dangers will increase day by day.
[0104] In automated testing, existing testing frameworks on the market cannot well detect such problems. An automated testing framework is a collection of tools composed of one or more automated testing basic modules, automated testing management modules, automated testing statistics modules, etc., which can be used to test test cases.
[0105] Currently commonly used testing frameworks include: shUnit2 testing framework and bats testing framework.
[0106] Construct test cases and use the shUnit2 testing framework to test the situations in [Scenario 1] to [Scenario 5] above. The test cases are specifically as follows:
[0107] #! / bin / sh
[0108] #file:examples / equality_test.sh
[0109] oneTimeSetUp(){
[0110] echo True>testfile1
[0111] }
[0112] # Test case 1
[0113] test1(){
[0114] assertTrue"cat testfile1|grep True"
[0115] }
[0116] # Test case 2
[0117] test2(){
[0118] assertFalse "cat testfile1|grep False"
[0119] }
[0120] # Test case 3
[0121] test3(){
[0122] assertFalse "cat testfile2|grep False"
[0123] }
[0124] # Test case 4
[0125] test4(){
[0126] assertTrue "cat testfile1|sed's / True / False / g'"
[0127] }
[0128] # Test case 5
[0129] test5(){
[0130] assertTrue "cat testfile2|sed's / True / False / g'"
[0131] }
[0132] oneTimeTearDown(){
[0133] rm -f testfile1
[0134] }
[0135] # Load and run shUnit2.
[0136] ... / shunit2
[0137] The test results obtained by executing the above test cases are as follows:
[0138] test1
[0139] test2
[0140] test3
[0141] test4
[0142] test5
[0143] Ran 5 tests.
[0144] OK
[0145] From the above execution results, it can be seen that all 5 test cases have passed. However, the execution results of [Test Case 3] and [Test Case 5] are incorrect because the directory testfile2 does not exist. This is an abnormal command, but the test result of the test case is passed, which is obviously an invalid test and cannot reflect the real test situation.
[0146] Next, construct test cases to test the above situations of [Scenario 1] to [Scenario 5] using the bats test framework. The specific test cases are as follows:
[0147] #! / usr / bin / env bats
[0148] setup(){
[0149] echo True>testfile1
[0150] }
[0151] # Test Case 1
[0152] @test "test1"{
[0153] run cat testfile1|grep True
[0154] [$status -eq 0]
[0155] }
[0156] # Test Case 2
[0157] @test "test2"{
[0158] run cat testfile1|grep False
[0159] [$status -ne 0]
[0160] }
[0161] # Test Case 3
[0162] @test "test3"{
[0163] run cat testfile2|grep False
[0164] [$status -ne 0]
[0165] }
[0166] # Test Case 4
[0167] @test "test4" {
[0168] run cat testfile1 | sed's / True / False / g'
[0169] [$status - ne 0]
[0170] }}
[0171] # Test case 5
[0172] @test "test5" {
[0173] run cat testfile2 | sed's / True / False / g'
[0174] [$status - ne 0]
[0175] }}
[0176] teardown() {
[0177] rm -f testfile1
[0178] }}
[0179] The test results obtained by executing the above test cases are as follows:
[0180] × test1
[0181] (in test file test1.bats, line 11)
[0182] run cat testfile1 | grep True'failed
[0183] × test2
[0184] (in test file test1.bats, line 18)
[0185] run cat testfile1 | grep False'failed
[0186] × test3
[0187] (in test file test1.bats, line 25)
[0188] run cat testfile2 | grep False'failed
[0189] × test4
[0190] (in test file test1.bats, line 32)
[0191] [$status - eq 0]'failed with status 2
[0192] ×test5
[0193] (in test file test1.bats, line 38)
[0194] [$status - eq 0]'failed with status 2
[0195] 5 tests, 5 failures
[0196] According to the test results, it can be seen that the results of all test commands are failures. Obviously, when the test commands contain pipe symbols, it will affect the framework's judgment of the test results.
[0197] Next, construct test cases to test the above scenarios 1 to 3 without pipe symbols using the bats test framework. The specific test cases are as follows:
[0198] #! / usr / bin / env bats
[0199] setup() {
[0200] echo True > testfile1
[0201] }
[0202] # Test case 1
[0203] @test "test1" {
[0204] run grep True testfile1
[0205] [$status - eq 0]
[0206] }
[0207] # Test case 2
[0208] @test "test2" {
[0209] run grep False testfile1
[0210] [$status - ne 0]
[0211] }
[0212] # Use Case 3
[0213] @test "test3" {
[0214] run grep False testfile2
[0215] [$status - ne 0]
[0216] }
[0217] teardown() {
[0218] rm -f testfile1
[0219] }
[0220] The test results obtained by executing the above test cases are as follows:
[0221] √test1
[0222] √test2
[0223] √test3
[0224] 3 tests, 0 failures
[0225] Now the test can be successful, but like the shUnit2 test framework, the test result of Use Case 3 is also incorrect, and the abnormal command is not recognized. Moreover, there are certain limitations in the test scenarios of this framework. There are many scenarios using pipelines in actual tests, such as multiple data processing and commands requiring human - machine interaction, etc., so it cannot meet the current test scenarios.
[0226] To solve the above - mentioned technical problems, the present invention provides a command test method for performing various tests using commands. The command test method of the present invention is suitable for execution in a computing device, such as being executed in computing device 100. First, the command to be tested is parsed to determine whether the command includes a connector and a query command.
[0227] The present invention parses the command to be tested, judges the inclusion of the connector and the query command therein, and uses different judgment logics for command testing. According to an embodiment of the present invention, the command to be tested can be implemented as a shell command and input into the computing device through shell module 122 for execution. The present invention does not limit the specific command types and input methods of the command to be tested.
[0228] When the present invention conducts command testing, it defines the types of status codes and their corresponding meanings. The status codes include a first status code and a second status code; among them: the first status code is used to indicate successful testing; the second status code is used to indicate failed testing. Further, the specific meaning of successful testing is that the execution of the command conforms to the correct expectation. For example, after the correct command is executed, the correct result (including return value, status code, etc.) is obtained, and after the wrong command is executed, the wrong result is obtained. During the normal testing process, sometimes it is also necessary to test wrong commands, and the wrong results obtained after the wrong commands are executed also have practical significance. The wrong result obtained from the wrong command indicates that the program under test is normal, and the next-stage targeted testing can be carried out according to the wrong result, such as improving the wrong command handling ability of the target under test (including applications or files) and improving the fault tolerance ability. Therefore, the wrong result obtained from the wrong command is also regarded as a successful test by the tester and is indicated by the first status code.
[0229] The specific meaning of failed testing is that the execution of the command does not conform to the correct expectation, which is a situation of execution error. For example, after the correct command is executed, the wrong result is obtained, and after the wrong command is executed, the correct result is obtained. The correct result obtained after the wrong command is executed instead indicates that the program under test is problematic and abnormal. Therefore, the correct result obtained after the wrong command is executed is also regarded as a failed test by the tester and is indicated by the second status code.
[0230] According to an embodiment of the present invention, when defining the first status code and the second status code, the first status code can be set to 0, and the second status code can be set to a non-zero value, such as 1, etc. The present invention does not limit the specific set fields or values of the first status code and the second status code, and developers or testers can customize them according to specific testing needs. The definition method of the status code can be defined by defining variables or by passing parameters when executing commands, and the present invention does not limit the definition method of the status code.
[0231] When parsing the command to be tested, by classifying and discussing the situation of the command containing connectors and query commands, and selecting different judgment logics according to different situations of containing connectors and query commands to obtain the returned status code, the customized returned status code with test reference significance covering different types of commands is realized.
[0232] According to an embodiment of the present invention, the situations where the command contains connectors and query commands include the following:
[0233] It does not contain a connector and does not contain a query command;
[0234] It contains a query command and does not include a connector
[0235] Contains a connector and does not contain a query command;
[0236] Contains a connector and also contains a query command.
[0237] The present invention customizes the judgment logic for the above several situations respectively to obtain the returned status code to indicate whether the test is successful or failed.
[0238] According to an exemplary embodiment of the present invention, the query command includes: the grep command. The grep command is used to find the strings that meet the conditions in the file. The present invention does not limit the specific type of the query command.
[0239] According to an exemplary embodiment of the present invention, the connector includes the pipe symbol "|". The present invention does not limit the specific type of the connector.
[0240] Figure 3 Shows a schematic diagram of parsing the command to be tested according to an exemplary embodiment of the present invention. As Figure 3 shown: After defining the command type, when receiving the input command, parse whether the command includes a query command and a connector. The query command includes the grep command, and the connector includes the pipe symbol.
[0241] Select different judgment processes according to the inclusion situation of the query command and the connector in the command, and make judgments according to different judgment logics; specifically:
[0242] When the command does not include the pipe symbol and does not include the grep command, select the first process;
[0243] When the command does not include the pipe symbol and includes the grep command, select the second process;
[0244] When the command includes the pipe symbol and does not include the grep command, select the third process;
[0245] When the command includes the pipe symbol and the grep command, select the fourth process;
[0246] Correspondingly execute different processes. After executing different judgment logics, output the redefined status code.
[0247] According to an embodiment of the present invention, when returning the defined first status code or second status code, the output content of the executed command can also be saved and / or output, so as to judge the execution situation of the command according to the returned status code and the output content, and obtain the output result of the test at this time.
[0248] Next, the command test method of the present invention will be further described. If after parsing the command, it is determined that it does not include a separator and a query command, then execute the command to obtain a status code. The obtained status code may be the first status code or the second status code.
[0249] If the obtained status code is the first status code indicating that the command is executed normally, then determine whether the command is a correct command. If the obtained status code is the first status code, it means that this command is executed normally and no problems occur during the execution process, so it is determined whether the command is correct.
[0250] If the command is a correct command, directly return the obtained first status code, indicating that the test is successful, and the tester can obtain the conclusion that the test is successful, and the correct command is executed normally.
[0251] According to an embodiment of the present invention, if the command is an incorrect command but the first status code is obtained, it means that the target under test runs the incorrect command and gets the correct result at this time. This is obviously an error in the target under test. At this time, modify the status code to the second status code and return it, indicating that the test fails.
[0252] According to an embodiment of the present invention, if the second status code indicating that the command execution is abnormal is obtained when executing the command, it means that the command is not executed normally at this time, and determine whether the command is a correct command.
[0253] If the command is a correct command, return the second status code, indicating that the test fails. If the command is a correct command, but the target under test does not execute this instruction normally, it means that there is a problem with the target under test and further testing is required. Return the second status code to inform the tester.
[0254] If the command is an incorrect command, modify the status code to the first status code and return it, indicating that the test is successful. If the command is not an incorrect command and an error occurs during execution to obtain the second status code, then the test result meets the test expectation, proving that the test is successful.
[0255] Figure 4 Shows a schematic diagram of the first process according to an exemplary embodiment of the present invention. As Figure 4 shown: When the command does not include a pipe symbol and does not include a grep command, execute the command and judge the obtained status code. If the status code is 0, determine whether the command is a correct command. If the command is a correct command, return the status code 0, indicating that the test is successful; if the command is an incorrect command, modify the status code to 1 and return it, indicating that the test fails. If the status code obtained after executing the command is 1, determine whether the command is a correct command. If the command is a correct command, return the status code 1; if the command is an incorrect command, modify the status code to 0 and return it.
[0256] According to an embodiment of the present invention, when returning the first status code or the second status code, the output content of the command is returned, so as to judge the test result according to the status code and the output content.
[0257] According to an embodiment of the present invention, when parsing a command, if the command includes a query command, the command is executed to obtain a status code; if the status code is the first status code, it is judged whether the command is a correct command; if the command is a correct command, the first status code is returned to indicate that the test is successful. If the obtained status code is the first status code, it means that the command is executed normally and no problems occur during the execution process, then it is judged whether the command is correct. If the command is a correct command, the obtained first status code is directly returned to indicate that the test is successful, and the tester can obtain the conclusion that the test is successful, and the correct command is executed normally and completed.
[0258] If the command is an incorrect command, the status code is modified to the second status code and returned to indicate that the test fails. If the command is an incorrect command but the first status code is obtained, it means that the target under test has obtained the correct result when executing the incorrect command, which is obviously an error of the target under test. At this time, the status code is modified to the second status code and returned to indicate that the test fails.
[0259] According to an embodiment of the present invention, if the status code is the second status code, it is judged whether the command is a correct command; if the command is a correct command, it is judged whether the output content of the command is empty; if the output content of the command is empty, the status code is modified to the first status code and returned to indicate that the test is successful. Since after the query command is executed, if the target keyword is successfully queried, the output content is empty. If the command is a correct command and the execution is successful and the output content is empty, the status code is modified to the second status code to inform the tester that the test is successful this time.
[0260] If the target keyword is not queried, the output content is not empty. If the output content is not empty, it means that the output content is an incorrect output and there is a problem with the command execution. Therefore, if the output content of the command is not empty, the second status code is returned to indicate that the test fails.
[0261] Furthermore, if the second status code is obtained after the command is executed, when judging whether the command is correct, if the command is an incorrect command, it is judged whether the output content of the command is empty; if the output content of the command is empty, the second status code is returned to indicate that the test fails. Since the command is an incorrect command, when executing the query command at this time, it should execute with an error and the output content should not be empty; and the output content of the command being empty does not conform to the test expectation, so the second status code is returned to indicate that there is a problem with the test.
[0262] If the output content of the command is not empty, modify the status code to the first status code and return it, indicating that the test is successful. If the command is an incorrect command and the output content is not empty, and the output content meets the expectations, then the test result is the desired result. Modify the status code to the first status code and return it.
[0263] Figure 5 The figure shows a schematic diagram of a second process according to an exemplary embodiment of the present invention. As Figure 4 shown: When the command does not include a pipe symbol and includes a grep command, execute the command and judge the obtained status code. If the status code is 0, judge whether the command is a correct command. If the command is a correct command, return the status code 0, indicating that the test is successful; if the command is an incorrect command, modify the status code to 1 and return it, indicating that the test fails. If the status code obtained after executing the command is 1, judge whether the command is a correct command. If the command is a correct command, judge whether the output content is empty; if the output content is empty, modify the status code to 0 and return it; if the output content is not empty, return the status code 1.
[0264] Furthermore, if the status code is 1 and when judging whether the command is a correct command, the command is an incorrect command, then judge whether the output content is empty. If the output content is empty, return the status code 1; if the output content is not empty, modify the status code to 1 and return it.
[0265] According to an embodiment of the present invention, when parsing a command, if the command includes a connection symbol, execute the command to obtain a status code; if the command includes a connection symbol, set the command return logic and execute the command to obtain a status code. The command return logic is used to limit the type of status code returned by the executed command. Specifically: the command return logic includes: if the sub-command status code returned by the execution of one or more sub-commands in the command is the second status code, then the status code is the second status code.
[0266] Since when the command includes a connection symbol, the status code finally returned by the command depends on the execution situation of the last sub-command in the command. If the last sub-command is executed successfully, even if the previous sub-commands are executed unsuccessfully, the final status code will be the first status code, indicating that the execution situation of the entire command is successful execution. To avoid the above situation, set the command return logic. When setting the command return logic, regardless of the number of sub-commands included in the command, as long as one sub-command in the command fails to execute, the entire command is regarded as failed, and the returned status code is the second status code.
[0267] According to an embodiment of the present invention, when setting the command return logic, it can be set through the command set and by configuring the parameter -opipefail. The present invention does not limit the specific setting method when setting the command return logic.
[0268] After the command is executed, if the status code is the first status code, it is determined whether the command is a correct command; if the command is a correct command, the first status code is returned, indicating that the test is successful. If the obtained status code is the first status code, it means that the command is executed normally and there are no problems during the execution process, so it is determined whether the command is correct. If the command is a correct command, the obtained first status code is directly returned, indicating that the test is successful, and the tester can obtain the conclusion that the test is successful, and the correct command is executed normally to completion.
[0269] If the command is an incorrect command, the status code is modified to the second status code and returned, indicating that the test has failed. If the command is an incorrect command but the first status code is obtained, it means that the target under test has obtained the correct result when running the incorrect command, which is obviously an error in the target under test. At this time, the status code is modified to the second status code and returned, indicating that the test has failed.
[0270] Furthermore, if the status code obtained after the command is executed is the second status code, it is determined whether the command is a correct command; if the command is a correct command, the second status code is returned, indicating that the test has failed. If the command is a correct command but the target under test does not execute the instruction normally, it means that there is a problem with the target under test and further testing is required. The second status code is returned to inform the tester.
[0271] If the command is an abnormal command, the status code is modified to the first status code and returned, indicating that the test is successful. If the command is an incorrect command and an error occurs during execution to obtain the second status code, the test result meets the test expectation, proving that the test is successful.
[0272] When the command includes a connector, set the command return logic. After returning the first status code or the second status code after the test is completed, delete the command return logic to avoid affecting the test process in other cases.
[0273] According to an embodiment of the present invention, when deleting the command return logic, it can be set by the command set and configuring the parameter +opipefail. The present invention does not limit the specific setting method when deleting the command return logic.
[0274] Figure 6 Shows a schematic diagram of the third process according to an exemplary embodiment of the present invention. As Figure 6 shown: When the command includes a pipe symbol and does not include the grep command, set the command return logic by the command set and configuring the parameter -opipefail, and execute the command. Judge the status code obtained after executing the command. If the status code is 0, judge whether the command is a correct command. If the command is a correct command, return the status code 0, indicating that the test is successful; if the command is an incorrect command, modify the status code to 1 and return it, indicating that the test has failed.
[0275] Further, if the status code is 1, it is determined whether the command is a correct command. If the command is a correct command, the status code 1 is returned; if the command is an incorrect command, the status code is modified to 0 and returned.
[0276] After the test is completed, the command return logic is deleted by using the command set and configuring the parameter +o pipefail to avoid affecting the test process of other situations.
[0277] The following combines Figure 2 Details of each step in the command test method 200 are introduced.
[0278] Figure 2 FIG. shows a schematic flowchart of a command test method 200 according to an exemplary embodiment of the present invention. As Figure 2 shown, first, step S210 is executed to parse the command to be tested to determine whether the command includes a separator and a query command.
[0279] Subsequently, step S220 is executed. When parsing the command, if the command includes a separator and a query command, the command return logic is set and the command is executed to obtain a status code. Then, step S230 is executed to determine whether the query command is the last command in the command;
[0280] Next, step S240 is executed: if the query command is not the last command in the command and the status code is the first status code, it is determined whether the command is a correct command;
[0281] Finally, step S250 is executed: if the command is a correct command, the first status code is returned, indicating that the test is successful.
[0282] Since the command includes a separator, the command return logic is still set before the test when testing this command. Since the combined effect of the separator and the query command affects the test result, a case-by-case discussion is made on the position of the query command in the command.
[0283] When the query command is in the middle of the command rather than the last sub-command of the command, the output of the query command will be used as the input of the subsequent command. When there is a problem with the output of the query command, the subsequent command cannot be executed normally. Therefore, the status code obtained by executing the subsequent command becomes unreliable and cannot provide an accurate test result, and further detailed testing is required.
[0284] When the query command is not the last command in the command sequence, but the obtained status code is the first status code, it indicates that the command is executed normally without any problems during the execution process. Then, it is necessary to determine whether the command is correct. If the command is a correct command, directly return the obtained first status code, indicating that the test is successful, and the tester can draw the conclusion that the test is successful, and the correct command is executed successfully.
[0285] If the command is an incorrect command, modify the status code to the second status code and return it, indicating that the test fails. Since there is a problem with the query command or other sub-commands in the command, the output of the query command is incorrect and cannot provide accurate input for subsequent commands. Therefore, the obtained first status code is unreliable. Modify the first status code to the second status code and return it, indicating that the test fails. If the query command is not the last command in the command sequence and the status code is the second status code, then return the second status code. In this case, when the command is correct but the second status code is obtained, it means that the target under test did not execute the instruction normally, and there is a problem with the target under test, and further testing is required. Return the second status code to inform the tester.
[0286] When the command is incorrect, since the output provided by the incorrect command is inaccurate and cannot provide accurate input for subsequent commands, the final status code is no longer reliable and cannot provide accurate test results, and further detailed testing is required. In this case, an incorrect command not only refers to an incorrect query command but also includes incorrect sub-commands other than the last command.
[0287] If the query command is the last command in the command sequence, then determine whether the intermediate status code before executing the query command is the first status code; if the intermediate status code is not the first status code, then return the second status code, indicating that the test fails. If the query command is the last command, the input of the query command is the output of the command before the query command. The output of the query command no longer affects the execution of the entire command. Among them, the intermediate status code is the status code obtained after the execution of the command before the query command. If the intermediate status code is the first status code, it means that the commands before the query command are all executed normally. If the intermediate status code is not the first status code, but the second status code or other status codes, it means that there is a problem with the execution of the commands before the query command, and the output of other commands to the query command is incorrect. In this case, regardless of whether the query command is a correct command or an incorrect command, the obtained status code is no longer reliable; return the second status code for the tester to conduct further testing.
[0288] If the intermediate status code is the first status code and the status code is also the first status code, then determine whether the command is a correct command; if the command is a correct command, return the first status code, indicating that the test is successful. If both the queried intermediate status code and the status code are the first status code, it means that both the command before the query command and the query command are executed normally, and the query command is a correct command, then return the first status code to indicate that the test is successful, and the tester can obtain the conclusion that the test is successful, and the correct command is executed normally and completed.
[0289] If the command is an incorrect command, then modify the status code to the second status code and return it, indicating that the test fails. If the command is an incorrect command but the first status code is obtained, it means that the target under test has obtained the correct result when running the incorrect command, which is obviously an error in the target under test. At this time, modify the status code to the second status code and return it, indicating that the test fails.
[0290] If the intermediate status code is the first status code and the status code is the second status code, then determine whether the command is a correct command; if the command is a correct command, return the second status code, indicating that the test fails. If the intermediate status code is the first status code, it means that all the commands before the query command are executed normally and the query command has obtained accurate input. If the command is a correct command but the target under test does not execute this instruction normally, it means that there is a problem with the target under test and further testing is required. Return the second status code to inform the tester.
[0291] If the command is an incorrect command, then modify the status code to the first status code and return it, indicating that the test is successful. If the command is an incorrect command and an error occurs during execution and the second status code is obtained, then this test result meets the test expectation, proving that the test is successful.
[0292] After returning the first status code or the second status code, delete the command return logic to avoid affecting the test process in other cases.
[0293] Figure 7 Shows a schematic diagram of the fourth process according to an exemplary embodiment of the present invention. As Figure 7 shown, when the command includes a pipe character and includes the grep command, through the command set, and configure the parameter -opipefail to implement setting the command return logic and execute the command. If the last command in the pipe is a query command, then judge the status code obtained after executing the command. If the status code is 0, then judge whether the command is a correct command. If the command is a correct command, then return the status code 0, indicating that the test is successful; if the command is an incorrect command, then modify the status code to 1 and return it, indicating that the test fails.
[0294] Further, if the query command is not the last command in the commands, and the status code is 1, when the command is correct and the second status code is obtained, it indicates that the target under test did not execute the instruction properly, and there is a problem with the target under test. Further testing is required, and the second status code is returned to inform the tester.
[0295] When the command is incorrect, since the output provided by the incorrect command is not accurate and cannot provide accurate input for subsequent commands, the final status code is no longer reliable and cannot provide accurate test results. Further detailed testing is required. In this case, an incorrect command not only refers to an incorrect query command but also includes incorrect sub-commands other than the last command. Therefore, if the query command is not the last command in the commands and the status code is 1, regardless of whether the command is a correct command or an incorrect command, 1 is returned.
[0296] If the query command is the last command in the commands, then it is determined whether the intermediate status code obtained after the execution of other previous commands except the query command is 0. If the intermediate status code is 0, it means that there is a problem with the execution of the commands before the query command, and the output of other commands for the query command is problematic. In this case, regardless of whether the query command is a correct command or an incorrect command, the obtained status code is no longer reliable; 1 is returned for the tester to conduct further testing.
[0297] If the intermediate status code is 0 and the status code is also 0, then it is determined whether the command is a correct command; if the command is a correct command, 0 is returned; if the command is an incorrect command, 1 is returned. If the intermediate status code is 0, it means that the commands before the query command are all executed normally, and the query command has obtained accurate input.
[0298] If the intermediate status code is 0 while the status code is 1, then it is determined whether the command is a correct command; if the command is a correct command, 1 is returned; if the command is an incorrect command, 0 is returned.
[0299] According to the command execution method of the present invention, a single command can be tested. When there are multiple commands, each command can be tested in this way according to the method of the present invention to test multiple commands. The present invention does not limit the range of the number of commands used.
[0300] According to an embodiment of the present invention, if there are multiple commands in a test case, according to the command execution method of the present invention, if the status codes returned by all commands are 0, the entire test case passes; if one of the commands fails, the test case fails, and the status of this test case is marked for subsequent testing.
[0301] According to an embodiment of the present invention, test cases for the above [Scenario 1] to [Scenario 5] are constructed and tested according to the command execution method of the present invention. The test cases are specifically as follows:
[0302] #! / bin / bash
[0303] echo True > testfile1
[0304] test1() {
[0305] quiet "cat testfile1|grep True" "true" # Test command with the passed parameter "true / false" representing the command type
[0306] Com1="${quiet_s}" # Redefined status code
[0307] Com2="${quiet_r}" # Output content
[0308] Exp1="0"
[0309] Exp2="True"
[0310] assertEqual "${Com1}" "${Exp1}"
[0311] assertIn "${Exp2}" "${Com2}"
[0312] }
[0313] test2() { ......
[0315] quiet "cat testfile1|grep False" "false"
[0316] Com1="${quiet_s}"
[0317] Com2="${quiet_r}"
[0318] Exp1="0"
[0319] Exp2=""
[0320] assertEqual "${Com1}" "${Exp1}"
[0321] assertEqual "${Exp2}" "${Com2}"
[0322] }
[0323] test3() { ......
[0325] quiet "cat testfile2|grep False" "true"
[0326] Com = "${quiet_s}"
[0327] Exp1 = "0"
[0328] Exp2 = ""
[0329] assertEqual "${Com1}" "${Exp1}"
[0330] assertEqual "${Exp2}" "${Com2}"
[0331] }
[0332] test4() { ......
[0334] quiet "cat testfile1|sed's / True / False / g'" "true" Com = "${quiet_r}"
[0335] Exp = "False"
[0336] assertEqual "${Com}" "${Exp}"
[0337] }
[0338] test5() { ......
[0340] quiet "cat testfile2|sed's / True / False / g'" "true"
[0341] Com = "${quiet_r}"
[0342] Exp = "False"
[0343] assertEqual "${Com}" "${Exp}"
[0344] }
[0345] rm -f testfile1
[0346] Figure 8 A schematic diagram showing the test case execution result according to an exemplary embodiment of the present invention is shown. As Figure 8As shown, Use Case 1, Use Case 2, and Use Case 4 passed the test, while Use Case 3 and Use Case 5 both failed the test. The test results of all the use cases used conform to the expected results. Therefore, the present invention can accurately identify anomalies, avoid the problem that the test results of abnormal use cases pass, and can quickly identify the quality risks of use case codes. Here, the status of the use cases with problems in the test is "error", indicating that there are anomalies in the test commands in the use cases. This use case needs to be further tested and inspected to determine whether the reason is a change in the test environment or a change in requirements resulting in a change in the command, etc.
[0347] The present invention redesigned the test method for problems occurring in command testing. When this design method is used to execute test commands, a large amount of logical processing will be performed inside the method, the status code will be redefined, abnormal commands will be quickly identified, providing support for the testing of abnormal commands. While retaining the support for the maximum test scenarios, accurate and reliable test results can ultimately be provided.
[0348] The present invention discloses a command testing method suitable for execution in a computing device. One or more applications are running in the computing device. The method includes the steps of: parsing the command to be tested to determine whether the command includes a connector and a query command; if the command includes a connector and a query command, setting the command return logic and executing the command to obtain a status code; determining whether the query command is the last command in the command; if the query command is not the last command in the command and the status code is the first status code indicating normal command execution, determining whether the command is a correct command; if the command is a correct command, returning the first status code to indicate successful testing. The present invention parses the command to determine whether it includes a connector and a query command, and thus returns a status code according to the corresponding judgment logic, realizing a relatively accurate indication of the command execution situation by the status code.
[0349] In the specification provided herein, a large number of specific details are described. However, it can be understood that the embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures, and technologies are not shown in detail so as not to obscure the understanding of this specification.
[0350] Similarly, it should be understood that, in order to streamline this disclosure and assist in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof.
[0351] Those skilled in the art should understand that the modules or units or groups of the devices in the examples disclosed herein can be arranged in the devices as described in this embodiment, or alternatively can be located in one or more devices different from the devices in this example. The modules in the foregoing examples can be combined into one module or further divided into multiple sub-modules.
[0352] Those skilled in the art can understand that the modules in the devices in the embodiments can be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or groups in the embodiments can be combined into one module or unit or group, and in addition, they can be divided into multiple sub-modules or sub-units or sub-groups. Except that at least some of such features and / or processes or units are mutually exclusive, any combination can be adopted to combine all the features disclosed in this specification and all the processes or units of any method or device thus disclosed. Unless otherwise explicitly stated, each feature disclosed in this specification can be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0353] In addition, those skilled in the art can understand that although some of the embodiments described herein include certain features included in other embodiments rather than other features, the combination of the features of different embodiments means that it is within the scope of the present invention and forms different embodiments.
[0354] In addition, some of the embodiments herein are described as combinations of methods or method elements that can be implemented by a processor of a computer system or by other devices performing the functions. Therefore, a processor having the necessary instructions for implementing the method or method elements forms a device for implementing the method or method elements. In addition, the elements described herein in the device embodiments are examples of the following devices: the device is used to implement the functions performed by the elements for the purpose of implementing the present invention.
[0355] The various technologies described herein can be implemented in combination with hardware or software, or a combination thereof. Thus, the method and device of the present invention, or certain aspects or parts of the method and device of the present invention, can take the form of program code (i.e., instructions) embedded in a tangible medium, such as a floppy disk, CD-ROM, hard disk drive, or any other machine-readable storage medium, where when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes a device for practicing the present invention.
[0356] In the case where the program code is executed on a programmable computer, the computing device generally includes a processor, a processor-readable storage medium (including volatile and non-volatile memories and / or storage elements), at least one input device, and at least one output device. Among them, the memory is configured to store the program code; the processor is configured to execute the command test method of the present invention according to the instructions in the program code stored in the memory.
[0357] By way of example and not limitation, computer-readable media includes computer storage media and communication media. Computer-readable media includes computer storage media and communication media. Computer storage media stores information such as computer-readable instructions, data structures, program modules or other data. Communication media typically embodies computer-readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism, and includes any information delivery media. A combination of any of the above is also included within the scope of computer-readable media.
[0358] As used herein, unless otherwise specified, the use of ordinal numbers such as "first", "second", "third", etc. to describe a common object merely indicates different instances of similar objects and is not intended to imply that the objects so described must be in a given order, whether in terms of time, space, ranking, or in any other manner.
[0359] Although the invention has been described in terms of a limited number of embodiments, those skilled in the art, having the benefit of the foregoing description, will appreciate that other embodiments can be contemplated within the scope of the invention as thus described. Additionally, it should be noted that the language used in this specification has been principally selected for readability and instructional purposes and not for the purpose of explaining or limiting the subject matter of the invention. Accordingly, many modifications and variations will be apparent to those of ordinary skill in the art. The disclosure of the invention is illustrative, not restrictive, of the scope of the invention.
Claims
1. A command testing method, suitable for execution in a computing device, the method comprising the steps of: Parsing the command to be tested to determine whether the command includes a connector and a query command; If the command includes a connector and a query command, then set a command return logic and execute the command to obtain a status code; Determine whether the query command is the last command in the command; If the query command is not the last command in the command, and the status code is a first status code indicating normal command execution, then determine whether the command is a correct command; If the command is a correct command, then return the first status code, indicating successful testing.
2. The method according to claim 1, wherein The method further comprises the steps of: If the command is an incorrect command, then modify the status code to a second status code indicating abnormal command execution and return it, indicating failed testing.
3. The method according to claim 1, wherein, The method further comprises the steps of: If the query command is not the last command in the command, and the status code is the second status code, then return the second status code.
4. The method according to claim 1, wherein, The method further comprises the steps of: If the query command is the last command in the command, then determine whether the intermediate status code before executing the query command is the first status code; If the intermediate status code is not the first status code, then return the second status code, indicating failed testing.
5. The method according to claim 4, wherein, The method further comprises the steps of: If the intermediate status code is the first status code, and the status code is also the first status code, then determine whether the command is a correct command; If the command is a correct command, then return the first status code, indicating successful testing.
6. The method according to claim 5, wherein, The method further comprises the steps of: If the command is an incorrect command, then modify the status code to the second status code and return it, indicating failed testing.
7. The method according to claim 6, wherein, The method further comprises the steps of: If the intermediate status code is the first status code, and the status code is the second status code, then determine whether the command is a correct command; If the command is a correct command, then return the second status code, indicating failed testing.
8. The method according to claim 7, wherein, The method further comprises the steps of: If the command is an incorrect command, then modify the status code to the first status code and return it, indicating successful testing.
9. The method according to any one of claims 1-8, wherein The command return logic includes: If the sub-command status code returned by the execution of one or more sub-commands in the command is the second status code, then the status code is the second status code.
10. The method according to any one of claims 1-8, wherein, The method further comprises the steps of: After returning the first status code or the second status code, delete the command return logic.
11. The method according to any one of claims 1-8, wherein, The method further comprises the steps of: When returning the first status code or the second status code, return the output content of the command.
12. The method according to any one of claims 1-8, wherein, The query command includes: grep command.
13. The method according to any one of claims 1-8, wherein, The connector includes a pipe symbol.
14. A command testing method, suitable for execution in a computing device, the method comprising the steps of: Parsing the command to be tested to determine whether the command includes a connector and a query command; If the command includes a connector and does not include a query command, then set a command return logic and execute the command to obtain a status code; If the status code is the first status code, then determine whether the command is a correct command; If the command is a correct command, then return the first status code, indicating successful testing.
15. The method according to claim 14, wherein, The method further comprises the steps of: If the command is an incorrect command, modify the status code to a second status code and return it, indicating that the test fails.
16. The method according to claim 14, wherein, The method further includes the steps of: If the status code is the second status code, determine whether the command is a correct command; If the command is a correct command, return the second status code, indicating that the test fails.
17. The method according to claim 16, wherein, The method further includes the steps of: If the command is an abnormal command, modify the status code to a first status code and return it, indicating that the test succeeds.
18. A command testing method, suitable for execution in a computing device, the method including the steps of: Parse the command to be tested to determine whether the command includes a separator and a query command; If the command includes a query command and does not include a separator, execute the command to obtain a status code; If the status code is the first status code, determine whether the command is a correct command; If the command is a correct command, return the first status code, indicating that the test succeeds.
19. The method according to claim 18, wherein, The method further includes the steps of: If the command is an incorrect command, modify the status code to a second status code and return it, indicating that the test fails.
20. The method according to claim 18, wherein, The method further includes the steps of: If the status code is the second status code, determine whether the command is a correct command; If the command is a correct command, determine whether the output content of the command is empty; If the output content of the command is empty, modify the status code to a first status code and return it, indicating that the test succeeds.
21. The method according to claim 20, wherein, The method further includes the steps of: If the output content of the command is not empty, return the second status code, indicating that the test fails.
22. The method according to claim 20, wherein, The method further includes the steps of: If the command is an incorrect command, determine whether the output content of the command is empty; If the output content of the command is empty, return the second status code, indicating that the test fails.
23. The method according to claim 22, wherein, The method further includes the steps of: If the output content of the command is not empty, modify the status code to a first status code and return it, indicating that the test succeeds.
24. A command testing method, suitable for execution in a computing device, the method including the steps of: Parse the command to be tested to determine whether the command includes a separator and a query command; If the command does not include a separator and a query command, execute the command to obtain a status code; If the status code is the first status code indicating normal command execution, determine whether the command is a correct command; If the command is a correct command, return the first status code, indicating that the test succeeds.
25. The method according to claim 24, wherein, The method further includes the steps of: If the command is an incorrect command, modify the status code to a second status code and return it, indicating that the test fails.
26. The method according to claim 25, wherein, The method further includes the steps of: If the status code is the second status code indicating abnormal command execution, determine whether the command is a correct command; If the command is a correct command, return the second status code, indicating that the test fails.
27. The method according to claim 26, wherein, The method further includes the steps of: If the command is an incorrect command, modify the status code to a first status code and return it, indicating that the test succeeds.
28. A computing device, including: One or more processors; A memory; And One or more devices, the one or more devices including instructions for performing the method according to any one of claims 1-27.
29. A computer-readable storage medium storing one or more programs, the one or more programs including instructions that, when executed by a computing device, cause the computing device to perform the method according to any one of claims 1-27.
Citation Information
Patent Citations
Retrieval method and retrieval device
CN104331517A
Log data analysis method and device based on dynamic sensing and readable storage medium
CN108920575A