SlideShare a Scribd company logo
1 of 20
Download to read offline
Bash is Testing @mt165pro
Testing in Bash
Matt Turner
@mt165pro
mt165.co.uk
DevOps Days London
September 2018
aka Bash is Testing
Bash is Testing @mt165pro
# A command has has a stdout, a stderr, and an exit code
2
Bash is Testing @mt165pro
# All commands have a return value
# No matter what they write to stdout or stderr
$ ls
foo bar
$ echo $?
0
3
Bash is Testing @mt165pro
# Usually commands succeed
# Even when they don’t, you often don’t care
$ grep “needle” haystack
grep: haystack: No such file or directory
$ echo $?
2
4
Bash is Testing @mt165pro
# How do you test success / failure in a script?
$ if true; then echo “yes”; else echo “no”; fi
yes
5
Bash is Testing @mt165pro
# if is a piece of bash syntax
# it “takes precisely one argument: a command that returns 0 or non-0”
# … a command that returns 0 or non-0
6
Bash is Testing @mt165pro
$ which true
/bin/true
# true: “does nothing, successfully” [man(1) true, 1991]
$ file /bin/true
/bin/true: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 3.2.0, BuildID[sha1]=cae1cea2c8b5f2d151aceb44bcbe1d8415bc06c5,
stripped
7
Bash is Testing @mt165pro
$ if which flibble; then echo “yes”; echo echo “no” fi
No
# which is a command. A unary one
$ which which
/usr/bin/which
8
Bash is Testing @mt165pro
# These commands can be combined with boolean operators
# which are part of the bash syntax
# they are: ! && ||
$ if which foo || which bar; then echo “yes”; fi
9
Bash is Testing @mt165pro
# you may have seen script like this:
$ if [ “a” == “b” ]; then echo “hello”; fi
10
Bash is Testing @mt165pro
$ which [
/usr/bin/[
11
Bash is Testing @mt165pro
$ if [ -x foo ]; then echo “yes”; fi
# /usr/bin/[ is the command
# its arguments are: -x, foo, … and ]
13
Bash is Testing @mt165pro
# what does this print?
$ if [ a && b ]; then echo “yes”; else echo “no”; fi
no
16
Bash is Testing @mt165pro
# what does this print?
$ if true -a ls; then echo “yes”; else echo “no”; fi
yes
17
Bash is Testing @mt165pro
# what about this one?
$ if [ false ]; then echo “yes”; else echo “no”; fi
yes
18
Bash is Testing @mt165pro
# what about this one?
$ if [ false ]; then echo “yes”; else echo “no”; fi
yes
19
Bash is Testing @mt165pro
# syntaces can be combined
$ if [ -n “$foo” -a -f bar ] && which baz; then echo “yes”; fi
# but remember that code’s primary purpose is to be read...
20
Bash is Testing @mt165pro
# turns out, && and || are short-cct
$ if true || rm -rf /; then echo “you’re fine”; fi
# no if statement required
$ grep “needle” haystack && echo “found it”
# commonly used with /bin/[
$ [ -x foo ] && ./foo
# || even binds less tightly
$ [ -x foo ] && ./foo || echo “foo not executable”
# yay BODMAS
21
Bash is Testing @mt165pro
# turns out, && and || are short-cct
$ if true || rm -rf /; then echo “you’re fine”; fi
# no if statement required
$ grep “needle” haystack && echo “found it”
# commonly used with /bin/[
$ [ -x foo ] && ./foo
# || even binds less tightly
$ [ -x foo ] && ./foo || echo “foo not executable”
# yay BODMAS
22
Bash is Testing @mt165pro
Bash is Testing
26

More Related Content

Similar to Bash is Testing

Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un UnixVpmv
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?Lloyd Huang
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25Techvilla
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on LinuxTushar B Kute
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XSbyterock
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 

Similar to Bash is Testing (20)

Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un Unix
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
 
KT on Bash Script.pptx
KT on Bash Script.pptxKT on Bash Script.pptx
KT on Bash Script.pptx
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
03 tk2123 - pemrograman shell-2
03   tk2123 - pemrograman shell-203   tk2123 - pemrograman shell-2
03 tk2123 - pemrograman shell-2
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Bash production guide
Bash production guideBash production guide
Bash production guide
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
Bash
BashBash
Bash
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

More from Matt Turner

The Life of a Packet through Istio III
The Life of a Packet through Istio IIIThe Life of a Packet through Istio III
The Life of a Packet through Istio IIIMatt Turner
 
Automated Cloud-Native Incident Response with Kubernetes and Service Mesh
Automated Cloud-Native Incident Response with Kubernetes and Service MeshAutomated Cloud-Native Incident Response with Kubernetes and Service Mesh
Automated Cloud-Native Incident Response with Kubernetes and Service MeshMatt Turner
 
apiserver-Only "Clusters" for fun and profit
apiserver-Only "Clusters" for fun and profitapiserver-Only "Clusters" for fun and profit
apiserver-Only "Clusters" for fun and profitMatt Turner
 
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenarios
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenariosIstio + SPIRE for cross-domain traffic trust in hybrid-cloud scenarios
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenariosMatt Turner
 
Why Is Istio That Shape?
Why Is Istio That Shape?Why Is Istio That Shape?
Why Is Istio That Shape?Matt Turner
 
Dynamically Testing Individual Microservice Releases In Production
  Dynamically Testing Individual Microservice Releases In Production  Dynamically Testing Individual Microservice Releases In Production
Dynamically Testing Individual Microservice Releases In ProductionMatt Turner
 
Gateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API GatewaysGateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API GatewaysMatt Turner
 
The Life of a Packet III - Service Mesh London
The Life of a Packet III - Service Mesh LondonThe Life of a Packet III - Service Mesh London
The Life of a Packet III - Service Mesh LondonMatt Turner
 
Cloud-Native Progressive Delivery
Cloud-Native Progressive DeliveryCloud-Native Progressive Delivery
Cloud-Native Progressive DeliveryMatt Turner
 
An Introduction to Bazel
An Introduction to BazelAn Introduction to Bazel
An Introduction to BazelMatt Turner
 
Networks, Linux, Containers, Pods
Networks, Linux, Containers, PodsNetworks, Linux, Containers, Pods
Networks, Linux, Containers, PodsMatt Turner
 
What is a Service Mesh and what can it do for your Microservices
What is a Service Mesh and what can it do for your MicroservicesWhat is a Service Mesh and what can it do for your Microservices
What is a Service Mesh and what can it do for your MicroservicesMatt Turner
 
Debugging an RBAC Problem in Istio
Debugging an RBAC Problem in IstioDebugging an RBAC Problem in Istio
Debugging an RBAC Problem in IstioMatt Turner
 
Running Resillient Workloads with Istio - KubeCon China 2019
Running Resillient Workloads with Istio - KubeCon China 2019Running Resillient Workloads with Istio - KubeCon China 2019
Running Resillient Workloads with Istio - KubeCon China 2019Matt Turner
 
Software Networking and Interfaces on Linux
Software Networking and Interfaces on LinuxSoftware Networking and Interfaces on Linux
Software Networking and Interfaces on LinuxMatt Turner
 
Running Resillient Workloads with Istio - OpenInfra Days 2019
Running Resillient Workloads with Istio - OpenInfra Days 2019Running Resillient Workloads with Istio - OpenInfra Days 2019
Running Resillient Workloads with Istio - OpenInfra Days 2019Matt Turner
 
The Life of a Packet through Istio - DevExperience Romania, April 2019
The Life of a Packet through Istio - DevExperience Romania, April 2019The Life of a Packet through Istio - DevExperience Romania, April 2019
The Life of a Packet through Istio - DevExperience Romania, April 2019Matt Turner
 
The life of a packet through Istio - QCon London 2019
The life of a packet through Istio - QCon London 2019The life of a packet through Istio - QCon London 2019
The life of a packet through Istio - QCon London 2019Matt Turner
 
Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019Matt Turner
 
Istio, The Packet's-Eye View - KubeCon NA 2018
Istio, The Packet's-Eye View - KubeCon NA 2018Istio, The Packet's-Eye View - KubeCon NA 2018
Istio, The Packet's-Eye View - KubeCon NA 2018Matt Turner
 

More from Matt Turner (20)

The Life of a Packet through Istio III
The Life of a Packet through Istio IIIThe Life of a Packet through Istio III
The Life of a Packet through Istio III
 
Automated Cloud-Native Incident Response with Kubernetes and Service Mesh
Automated Cloud-Native Incident Response with Kubernetes and Service MeshAutomated Cloud-Native Incident Response with Kubernetes and Service Mesh
Automated Cloud-Native Incident Response with Kubernetes and Service Mesh
 
apiserver-Only "Clusters" for fun and profit
apiserver-Only "Clusters" for fun and profitapiserver-Only "Clusters" for fun and profit
apiserver-Only "Clusters" for fun and profit
 
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenarios
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenariosIstio + SPIRE for cross-domain traffic trust in hybrid-cloud scenarios
Istio + SPIRE for cross-domain traffic trust in hybrid-cloud scenarios
 
Why Is Istio That Shape?
Why Is Istio That Shape?Why Is Istio That Shape?
Why Is Istio That Shape?
 
Dynamically Testing Individual Microservice Releases In Production
  Dynamically Testing Individual Microservice Releases In Production  Dynamically Testing Individual Microservice Releases In Production
Dynamically Testing Individual Microservice Releases In Production
 
Gateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API GatewaysGateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API Gateways
 
The Life of a Packet III - Service Mesh London
The Life of a Packet III - Service Mesh LondonThe Life of a Packet III - Service Mesh London
The Life of a Packet III - Service Mesh London
 
Cloud-Native Progressive Delivery
Cloud-Native Progressive DeliveryCloud-Native Progressive Delivery
Cloud-Native Progressive Delivery
 
An Introduction to Bazel
An Introduction to BazelAn Introduction to Bazel
An Introduction to Bazel
 
Networks, Linux, Containers, Pods
Networks, Linux, Containers, PodsNetworks, Linux, Containers, Pods
Networks, Linux, Containers, Pods
 
What is a Service Mesh and what can it do for your Microservices
What is a Service Mesh and what can it do for your MicroservicesWhat is a Service Mesh and what can it do for your Microservices
What is a Service Mesh and what can it do for your Microservices
 
Debugging an RBAC Problem in Istio
Debugging an RBAC Problem in IstioDebugging an RBAC Problem in Istio
Debugging an RBAC Problem in Istio
 
Running Resillient Workloads with Istio - KubeCon China 2019
Running Resillient Workloads with Istio - KubeCon China 2019Running Resillient Workloads with Istio - KubeCon China 2019
Running Resillient Workloads with Istio - KubeCon China 2019
 
Software Networking and Interfaces on Linux
Software Networking and Interfaces on LinuxSoftware Networking and Interfaces on Linux
Software Networking and Interfaces on Linux
 
Running Resillient Workloads with Istio - OpenInfra Days 2019
Running Resillient Workloads with Istio - OpenInfra Days 2019Running Resillient Workloads with Istio - OpenInfra Days 2019
Running Resillient Workloads with Istio - OpenInfra Days 2019
 
The Life of a Packet through Istio - DevExperience Romania, April 2019
The Life of a Packet through Istio - DevExperience Romania, April 2019The Life of a Packet through Istio - DevExperience Romania, April 2019
The Life of a Packet through Istio - DevExperience Romania, April 2019
 
The life of a packet through Istio - QCon London 2019
The life of a packet through Istio - QCon London 2019The life of a packet through Istio - QCon London 2019
The life of a packet through Istio - QCon London 2019
 
Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019
 
Istio, The Packet's-Eye View - KubeCon NA 2018
Istio, The Packet's-Eye View - KubeCon NA 2018Istio, The Packet's-Eye View - KubeCon NA 2018
Istio, The Packet's-Eye View - KubeCon NA 2018
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Bash is Testing

  • 1. Bash is Testing @mt165pro Testing in Bash Matt Turner @mt165pro mt165.co.uk DevOps Days London September 2018 aka Bash is Testing
  • 2. Bash is Testing @mt165pro # A command has has a stdout, a stderr, and an exit code 2
  • 3. Bash is Testing @mt165pro # All commands have a return value # No matter what they write to stdout or stderr $ ls foo bar $ echo $? 0 3
  • 4. Bash is Testing @mt165pro # Usually commands succeed # Even when they don’t, you often don’t care $ grep “needle” haystack grep: haystack: No such file or directory $ echo $? 2 4
  • 5. Bash is Testing @mt165pro # How do you test success / failure in a script? $ if true; then echo “yes”; else echo “no”; fi yes 5
  • 6. Bash is Testing @mt165pro # if is a piece of bash syntax # it “takes precisely one argument: a command that returns 0 or non-0” # … a command that returns 0 or non-0 6
  • 7. Bash is Testing @mt165pro $ which true /bin/true # true: “does nothing, successfully” [man(1) true, 1991] $ file /bin/true /bin/true: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=cae1cea2c8b5f2d151aceb44bcbe1d8415bc06c5, stripped 7
  • 8. Bash is Testing @mt165pro $ if which flibble; then echo “yes”; echo echo “no” fi No # which is a command. A unary one $ which which /usr/bin/which 8
  • 9. Bash is Testing @mt165pro # These commands can be combined with boolean operators # which are part of the bash syntax # they are: ! && || $ if which foo || which bar; then echo “yes”; fi 9
  • 10. Bash is Testing @mt165pro # you may have seen script like this: $ if [ “a” == “b” ]; then echo “hello”; fi 10
  • 11. Bash is Testing @mt165pro $ which [ /usr/bin/[ 11
  • 12. Bash is Testing @mt165pro $ if [ -x foo ]; then echo “yes”; fi # /usr/bin/[ is the command # its arguments are: -x, foo, … and ] 13
  • 13. Bash is Testing @mt165pro # what does this print? $ if [ a && b ]; then echo “yes”; else echo “no”; fi no 16
  • 14. Bash is Testing @mt165pro # what does this print? $ if true -a ls; then echo “yes”; else echo “no”; fi yes 17
  • 15. Bash is Testing @mt165pro # what about this one? $ if [ false ]; then echo “yes”; else echo “no”; fi yes 18
  • 16. Bash is Testing @mt165pro # what about this one? $ if [ false ]; then echo “yes”; else echo “no”; fi yes 19
  • 17. Bash is Testing @mt165pro # syntaces can be combined $ if [ -n “$foo” -a -f bar ] && which baz; then echo “yes”; fi # but remember that code’s primary purpose is to be read... 20
  • 18. Bash is Testing @mt165pro # turns out, && and || are short-cct $ if true || rm -rf /; then echo “you’re fine”; fi # no if statement required $ grep “needle” haystack && echo “found it” # commonly used with /bin/[ $ [ -x foo ] && ./foo # || even binds less tightly $ [ -x foo ] && ./foo || echo “foo not executable” # yay BODMAS 21
  • 19. Bash is Testing @mt165pro # turns out, && and || are short-cct $ if true || rm -rf /; then echo “you’re fine”; fi # no if statement required $ grep “needle” haystack && echo “found it” # commonly used with /bin/[ $ [ -x foo ] && ./foo # || even binds less tightly $ [ -x foo ] && ./foo || echo “foo not executable” # yay BODMAS 22
  • 20. Bash is Testing @mt165pro Bash is Testing 26