Онлайн-рабочие станции OnWorks Linux и Windows

Логотип

Бесплатный хостинг в Интернете для рабочих станций

<Предыдущая | Содержание: | Следующая>

Тестирование

Testing is an important step in every kind of software development, including scripts. There is a saying in the open-source world, “release early, release often,” which reflects this fact. By releasing early and often, software gets more exposure to use and testing.


Experience has shown that bugs are much easier to find, and much less expensive to fix, if they are found early in the development cycle.

In Chapter 26, we saw how stubs can be used to verify program flow. From the earliest stages of script development, they are a valuable technique to check the progress of our work.

Let’s look at the file-deletion problem above and see how this could be coded for easy testing. Testing the original fragment of code would be dangerous, since its purpose is to delete files, but we could modify the code to make the test safe:



если [[-d $ dir_name]]; тогда, если cd $ dir_name; тогда

эхо rm * # TESTING

еще

echo "не могу перейти к '$ dir_name'"> & 2 выйти 1

фи еще

echo "такого каталога нет: '$ dir_name'"> & 2 exit 1

fi

exit # TESTING

если [[-d $ dir_name]]; тогда, если cd $ dir_name; тогда

эхо rm * # TESTING

еще

echo "не могу перейти к '$ dir_name'"> & 2 выйти 1

фи еще

echo "такого каталога нет: '$ dir_name'"> & 2 exit 1

fi

exit # TESTING


Since the error conditions already output useful messages, we don't have to add any. The most important change is placing an эхо command just before the rm command to al- low the command and its expanded argument list to be displayed, rather than the com- mand actually being executed. This change allows safe execution of the code. At the end of the code fragment, we place an выход command to conclude the test and prevent any other part of the script from being carried out. The need for this will vary according to the design of the script.

We also include some comments that act as “markers” for our test-related changes. These can be used to help find and remove the changes when testing is complete.


 

Лучшие облачные вычисления для ОС в OnWorks: